/*出现两个按钮,预想是点击按钮press me时打印,点击按钮press me2时退出,
但运行时发现点击press me后先打印没按press me2就直接退出了
可是按press me2时却没有反应请帮忙看看*/
package Gui;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TestActinLister1 {
public static void main(String[] args) {
Frame f = new Frame();
Button b = new Button("press me");
Button b2 = new Button("press me2");
f.add(b,BorderLayout.CENTER);
f.add(b2,BorderLayout.NORTH);
Moniter m = new Moniter();
Moniter2 m2 = new Moniter2();
b.addActionListener(m);
b.addActionListener(m2);
f.pack();
f.setVisible(true);
}
}
class Moniter implements ActionListener
{
public void actionPerformed(ActionEvent e) {
System.out.println("____________hah");
}
}
class Moniter2 implements ActionListener
{
public void actionPerformed(ActionEvent e) {
System.exit(2);
}
}
|