从我的网易博客移动。。。。。
这个错误是一个内部类错误。。是指 内部类,实例化的时候要先实例化外部类。
原来的代码:
public class GraphicFrame extends Frame { public static void main(String[] args){ GraphicFrame rui = new GraphicFrame(); rui.addWindowListener(new Winadp());//这里发生了上述错误 } class Winadp extends WindowAdapter { public void windowClosing(WindowEvent e) { int ret = JOptionPane.showConfirmDialog(null, "是否退出?", "exit", JOptionPane.YES_NO_OPTION); if(ret == JOptionPane.YES_OPTION) { e.getWindow().setVisible(false); ((Window)e.getComponent()).dispose(); System.exit(0); } } }
修改就把错误的那句改为:
rui.addWindowListener(rui.new Winadp());
这样,就是调用了在已经实例化的外部类GraphicFrame的内部类。