小编nic*_*cki的帖子

JTextArea作为控制台

我在下面发布了两段代码.两个代码都可以单独使用.现在,当我运行文件Easy,然后单击"开始"按钮时,我希望实现类AddNumber.我的意思是说,而不是在控制台上运行的AddNumber,有没有什么方法可以让我在单击"开始"按钮后在第一个类中创建的JTextArea中运行AddNumber?我想也许是动作听众?(我们按钮的方式)但我不确定.有没有其他方法可以让我的JTextArea充当其他.java文件的控制台?

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;


public class Easy extends JFrame{

    JTextArea text=new JTextArea();
    JPanel panel=new JPanel(new GridLayout(2,2));

    JButton button1 =new JButton("Start");

    public Easy(){

        panel.add(text);

        panel.add(button1);
        add(panel,BorderLayout.CENTER);

        button1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae){
            //add code to call the other class and make the JTextArea act as a console
            }
        });
   }

   public static void main(String arg[]){
       Easy frame=new Easy();
       frame.setSize(300,100);
       frame.setVisible(true);
   }
}
Run Code Online (Sandbox Code Playgroud)

第二课:

import java.util.Scanner;

class AddNumber
{
    public static void main(String args[])
    {
        int x, y, …
Run Code Online (Sandbox Code Playgroud)

java console swing console-application jtextarea

6
推荐指数
1
解决办法
2万
查看次数

Python列表理解.替代/更好的方式来编写这段代码?

这是我正在使用的一个例子:

    >>> a = [('The','det'),('beautiful','adj')]
    >>> d = [y for (x,y) in a]
    >>> z = [x.lower() for (x,y) in a]
    >>> final=[]
    >>> final = zip(d,z)
    >>> final
    >>> [('det', 'the'), ('adj', 'beautiful')]
Run Code Online (Sandbox Code Playgroud)

这是直接从控制台工作时使用的好方法.如果我必须从.py文件运行它会怎么样?我想知道是否有一种有效/更好的方法来重写它,也许使用for循环?

python list-comprehension

0
推荐指数
1
解决办法
90
查看次数