class WindAction implements WindowListener
实现了这个接口,就必须实现里面的所有方法。

解决方案 »

  1.   

    java没你想象的那么厉害,呵呵
      

  2.   

    其实方法有很多,,我告诉你一种把。。不过要给我加分啊。。  :)在java里已经有一个现成的类WindowAdapter它已经空实现了WindowListener的所有的方法。。所以比想要用到它的哪个方法,就覆盖哪个方法就好了。。class WindAction extends WindowAdapter
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    }
    }
      

  3.   

    class WindAction extends WindowAdapter
    {
        public void windowCloseing(WindowEvent e)
        {
            System.exit(0);
        }
    }
      

  4.   

    //用户登陆窗体import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.event.WindowEvent;public class EntryFrame extends JFrame
    {
    JLabel JLabUserName = new JLabel();
    JLabel JLabUserPass = new JLabel();
    JTextField JTxtUserName = new JTextField();
    JTextField JTxtUserPass = new JTextField();
    JButton JButEnter = new JButton();
    JPanel JPan = new JPanel();
    GridLayout GriLay2 = new GridLayout(3,3);
    GridLayout GriLay1 = new GridLayout(5,1);
    public EntryFrame()
    {
    JPan.setSize(100,60);
    JPan.setLayout(GriLay1);
    JLabUserName.setText("用户名:");
    JLabUserName.setSize(60,20);
    JLabUserPass.setText("用户密码:");
    JLabUserPass.setSize(60,20);
    JTxtUserName.setSize(60,20);
    JTxtUserPass.setSize(60,20);
    JButEnter.setSize(60,20);
    JPan.add(JLabUserName);
    JPan.add(JTxtUserName);
    JPan.add(JLabUserPass);
    JPan.add(JTxtUserPass);
    JPan.add(JButEnter);
    this.getContentPane().setLayout(GriLay2);
    this.setContentPane(JPan);
    this.addWindowFocusListener(new WindAction());
    } class WindAction extends WindowAdapter
    {
    public void windowClosed(WindowEvent e)
    {
    System.exit(0);
    }
    }
    }//程序入口
    public class MainApp
    {
    public static void main(String[] args) throws Exception
    {
    EntryFrame EF=new EntryFrame();
    EF.setSize(300,200);
    EF.setVisible(true);
    }
    }
    按这样写了以后,我在主程序里实现了这个窗体后,按了X后窗体关闭的但是程序依然没有退出,怎么回事呢?
      

  5.   

    上面有个地方写错了
    this.addWindowListener(new WindAction());
    我是这样写的,问题依然存在.
      

  6.   

    不要这么复杂,内部类就不要了(仍要得话建议WindowAdapter,注意方法名的拼写)
    只要你的窗口是JFramesetDefaultCloseOperation(int)
    int 
    HIDE_ON_CLOSE //默认,自动隐藏
    DISPOSE_ON_CLOSE //建议,特别是对于多窗口程序
    EXIT_ON_CLOSE //在单窗口中与DISPOSE_ON_CLOSE表现起来一样
    DO_NOTHING_ON_CLOSE //表现起来与awt一样对你按[X],alt-F4没有任何反应