An action event occurs when the mouse is clicked and released;
Method summary:
actionPerformed(ActionEvent e)
Called when an operation occurs.
Column:
public class shijian extends Frame { public static void main(String[] args) { Frame f = new Frame(); f.setLayout(new FlowLayout(FlowLayout.LEFT,20,5)); Button b1 = new Button("单机"); Button b2 = new Button("双击"); //Button b3 = new Button("a3"); //创建监听器 myactionlistener m = new myactionlistener(); b1.addActionListener(m);//将m事件监听器注册个b1按钮 f.add(b1); f.add(b2); //f.add(b3); f.pack(); f.setVisible(true); } } class myactionlistener implements ActionListener//实现一个监听器类 { @Override public void actionPerformed(ActionEvent e) { System.out.println("单机一"); //System.exit(0); //用按钮关闭窗口 } }