当窗口大小发生改变时,原来不是触发 windowStateChanged 而是触发 ComponentAdapter。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MyFrame extends JFrame {
class MCA extends ComponentAdapter {
public void componentResized(ComponentEvent e) {
System.out.println("componentResized");
}
}
class MWA extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowStateChanged(WindowEvent e) {
System.out.println("windowStateChanged");
}
}
public MyFrame() {
super("Test");
addWindowListener(new MWA());
addComponentListener(new MCA());
setSize(200, 100);
setVisible(true);
}
public static void main(String[] args) {
MyFrame mf = new MyFrame();
}
}
搞了老半天,真郁闷。
本文地址:http://com.8s8s.com/it/it15177.htm