import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;public class WindowEventTest extends Frame implements ActionListener, WindowListener { Button b1 = new Button("ok");
TextField t1 = new TextField("mainclass"); public WindowEventTest() {
setLayout(new FlowLayout());
b1.addActionListener(this); setSize(200, 200);
setVisible(true);
add(b1);
add(t1);
addWindowListener(this);
} public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == b1) {
t1.setText("hello");
} } public void windowClosing(WindowEvent e) {
//System.exit(1);
this.dispose();
// int result=JOptionPane.showConfirmDialog(this,"请确认是否退出程序");
// if(result==JOptionPane.YES_OPTION){
// System.exit(0);
// } } public void windowActivated(WindowEvent e) {
System.out.println("activated");
} public void windowClosed(WindowEvent e) {
System.out.println("closed");
} public void windowDeactivated(WindowEvent e) {
System.out.println("deactivated");
} public void windowDeiconified(WindowEvent e) {
System.out.println("Deiconified"); } public void windowIconified(WindowEvent e) {
System.out.println("Iconified");
} public void windowOpened(WindowEvent e) {
System.out.println("Opened");
} public static void main(String[] args) {
new WindowEventTest();
}
}请教各位,为什么public void windowOpened(WindowEvent e) {
System.out.println("Opened");
} 不起作用 谢谢各位了
import java.awt.event.*;
import javax.swing.JOptionPane;public class WindowEventTest extends Frame implements ActionListener, WindowListener { Button b1 = new Button("ok");
TextField t1 = new TextField("mainclass"); public WindowEventTest() {
setLayout(new FlowLayout());
b1.addActionListener(this); setSize(200, 200);
setVisible(true);
add(b1);
add(t1);
addWindowListener(this);
} public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == b1) {
t1.setText("hello");
} } public void windowClosing(WindowEvent e) {
//System.exit(1);
this.dispose();
// int result=JOptionPane.showConfirmDialog(this,"请确认是否退出程序");
// if(result==JOptionPane.YES_OPTION){
// System.exit(0);
// } } public void windowActivated(WindowEvent e) {
System.out.println("activated");
} public void windowClosed(WindowEvent e) {
System.out.println("closed");
} public void windowDeactivated(WindowEvent e) {
System.out.println("deactivated");
} public void windowDeiconified(WindowEvent e) {
System.out.println("Deiconified"); } public void windowIconified(WindowEvent e) {
System.out.println("Iconified");
} public void windowOpened(WindowEvent e) {
System.out.println("Opened");
} public static void main(String[] args) {
new WindowEventTest();
}
}请教各位,为什么public void windowOpened(WindowEvent e) {
System.out.println("Opened");
} 不起作用 谢谢各位了
public WindowEventTest() {
setLayout(new FlowLayout());
b1.addActionListener(this); setSize(200, 200);
addWindowListener(this);
setVisible(true);
add(b1);
add(t1);
}
addWindowListener(this);
放在
setVisible(true);前面就行了
horizonlyhw真是这麽回事 非常感谢