刘伯阳 发表于 2012-6-2 14:11
京兄:你写的表现形式看起来是那样,不过你是只对JButton a进行监听,然后if判断。我想要的是点了个a之后 ...
按照你的意思又改了一下;P
import javax.swing.*;
import java.awt.event.*;
public class Test extends JFrame implements ActionListener {
JButton a = new JButton();
JButton b = new JButton();
JButton c = new JButton();
JPanel x = new JPanel();
int count = 1;
public Test() {
a.setText("你好");
this.setBounds(500, 200, 300, 200);
this.setTitle("窗口");
this.setVisible(true);
this.add(x);
x.add(a);
a.addActionListener(this);
a.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (count == 1) {
a.setVisible(false);
b.setText("HELLO");
this.setBounds(500, 200, 300, 200);
this.setVisible(true);
this.setTitle("窗口2");
x.add(b);
b.addActionListener(this);
} else {
b.setVisible(false);
c.setText("你好,HELLO");
this.setBounds(500, 200, 300, 200);
this.setVisible(true);
this.setTitle("窗口3");
x.add(c);
c.addActionListener(this);
}
count++;
}
public static void main(String args[]) {
Test a = new Test();
}
} |