62,614
社区成员
发帖
与我相关
我的任务
分享
package Swing2;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class EventDemo1 implements ActionListener,WindowListener {
public EventDemo1()
{
JFrame f=new JFrame("EventDemo1");
Container contentPane=f.getContentPane();
JButton b=new JButton("L can speak!");
b.addActionListener(this);
contentPane.add(b);
f.pack();
f.show(); //这里有一处警告!!!
f.addWindowListener(this);
}
public void actionPerformed(ActionEvent e)
{
Toolkit.getDefaultToolkit().beep();
}
public void windowIconified(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowOpened(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowClosing(WindowEvent e){
System.exit(0);
}
public static void main(String arg[])
{
new EventDemo1();
}
}