java中 设置两个TextArea 默认显示TextArea1, 然后点击按钮显示TextArea2
3个回答
展开全部
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class NewClass2 extends JFrame{
JButton jButton1;
JButton jButton2;
JTextArea jTextArea;
public NewClass2()
{
jButton1 = new JButton("JButton1");
jButton2 = new JButton("JButton2");
jTextArea = new JTextArea(null,"jtextarea",5,20);
this.add(jButton1);
this.add(jButton2);
this.add(jTextArea);
jButton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jTextArea.setText("jButton1");
}
});
jButton2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jTextArea.setText("jButton2");
}
});
this.setLayout(new FlowLayout());
this.setBounds(200, 100, 300, 170);
this.setVisible(true);
}
public static void main(String[] args)
{
new NewClass2();
}
}
import java.awt.event.*;
import java.awt.*;
public class NewClass2 extends JFrame{
JButton jButton1;
JButton jButton2;
JTextArea jTextArea;
public NewClass2()
{
jButton1 = new JButton("JButton1");
jButton2 = new JButton("JButton2");
jTextArea = new JTextArea(null,"jtextarea",5,20);
this.add(jButton1);
this.add(jButton2);
this.add(jTextArea);
jButton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jTextArea.setText("jButton1");
}
});
jButton2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jTextArea.setText("jButton2");
}
});
this.setLayout(new FlowLayout());
this.setBounds(200, 100, 300, 170);
this.setVisible(true);
}
public static void main(String[] args)
{
new NewClass2();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询