求java的编程答案,我会加分的~~~
来源:百度知道 编辑:UC知道 时间:2024/05/31 03:46:42
附:可能用到的工具:
WindowListener接口中包括的方法定义:
public void windowClosing(WindowEvent e);
public void windowOpened(WindowEvent e);
public void windowIconified(WindowEvent e);
public void windowDeiconified(WindowEvent e);
public void windowClosed(WindowEvent e);
public void windowActivated(WindowEvent e);
public void windowDeactivated(WindowEvent e);
ActionListener接口中包括的方法定义:
public void actionPerformed(ActionEvent e);
import javax.swing.*;
import java.awt.event.*;
class baidu extends JFrame{
JButton btnPressMe;
public baidu(){
super("Hello");
this.setLayout(null);
btnPressMe=new JButton("press me");
btnPressMe.setSize(100,30);
btnPressMe.addActionListener(new pressMe());
this.add(btnPressMe);
this.setSize(200, 200);
this.addWindowListener(new winClose());
this.setVisible(true);
}
public static void main(String[] args){
new baidu();
}
class pressMe implements ActionListener{
public void actionPerformed(ActionEvent ae){ /*响应单击事件*/
JOptionPane.showMessageDialog(null,"你好,欢迎进入Java世界!"); /*弹出对话框显示*/
}
}
class winClose implements WindowListener{
public void windowClosing(WindowEvent we){ /*响应windows窗体关闭事件*/
System.exit(0);
}
public void windowOpened(WindowEvent e){}
public voi