How to close the window in AWT?

前端 未结 3 2044
执念已碎
执念已碎 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:14

    It's better to use the method public void dispose()

    Why should you have to dispose() a java.awt.Window that goes out of scope?

    f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
                dispose();
             }
         }
    );
    

提交回复
热议问题