WindowAdapter抽象类中定义的需要被override的方法是
public void windowClosing(WindowEvent e)
首字母小写
如果在Eclipse中编写 有override标记提醒

解决方案 »

  1.   

    改好了,这个写关闭的时候最好用匿名类。import java.awt.*;
    import java.awt.event.*;public class FramTest { public static void main(String[] args) { Frame f = new Frame();
    f.setSize(600, 400);
    f.setLocation(100, 100);
    // f.setLayout(new BorderLayout(10,10));
    // f.setLayout(new FlowLayout(FlowLayout.LEFT));
    f.setLayout(new GridLayout(3, 2, 10, 10));
    f.setBackground(Color.blue);
    Button btn1 = new Button("N");
    Button btn2 = new Button("w");
    Button btn3 = new Button("d");
    Button btn4 = new Button("s");
    Button btn5 = new Button("b");
    f.add(btn1, "North");
    f.add(btn2, "South");
    f.add(btn3, "East");
    f.add(btn4, "West");
    f.add(btn5, "Center"); f.addWindowListener(new HisWindowListener());
    /*
     * f.addWindowListener(new WindowAdapter(){ public void
     * WindowClosing(WindowEvent e){ System.exit(0); } });
     */ f.addWindowListener(new WindowAdapter() { @Override
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    } });
    f.show(); }}class HisWindowListener extends WindowAdapter {
    public void WindowClosing(WindowEvent e) {
    System.exit(0);
    }
    }