How to close the window in AWT?

前端 未结 3 2073
执念已碎
执念已碎 2021-01-04 14:02

I am creating a small application using AWT. When I try to close the window, the \"close\" button doesn\'t work.

Here\'s my code:

import java.awt.*;
         


        
3条回答
  •  别那么骄傲
    2021-01-04 14:19

    Try doing it like this:

    class ExampleClass implements ActionListener, WindowListener
    {
    
    ...
    
    f.addWindowListener(this);
    
    ...
    
    public void windowDeactivated(WindowEvent e) {}
    public void windowDeiconified(WindowEvent e) {}
    public void windowIconified(WindowEvent e) {}
    public void windowOpened(WindowEvent e) {}
    public void windowActivated(WindowEvent e) {}
    public void windowClosed(WindowEvent e) {}
    
    public void windowClosing(WindowEvent e) 
    {
        System.exit(0);
    }
    
    }
    

提交回复
热议问题