import
javax.swing.
*
;
import java.awt.event. * ;
public class ActionFirst extends JFrame implements ActionListener ... {
public static void main(String[] args) ...{
new ActionFirst();
}
public void actionPerformed(ActionEvent e)...{
//静态方法。不用声明
JOptionPane.showMessageDialog(this,"小子你打错了。重来!!");
}
public ActionFirst() ...{
super("action first");
JButton b=new JButton("click");
this.getContentPane().add(b);
b.addActionListener(this);//注册监听
this.setSize(200,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//使关闭叉可用
}
}
import java.awt.event. * ;
public class ActionFirst extends JFrame implements ActionListener ... {
public static void main(String[] args) ...{
new ActionFirst();
}
public void actionPerformed(ActionEvent e)...{
//静态方法。不用声明
JOptionPane.showMessageDialog(this,"小子你打错了。重来!!");
}
public ActionFirst() ...{
super("action first");
JButton b=new JButton("click");
this.getContentPane().add(b);
b.addActionListener(this);//注册监听
this.setSize(200,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//使关闭叉可用
}
}