AWT Frame close using close Button

December 12, 2015 , 0 Comments

In AWT Java we have a Frame class which is inherit from window class. If you are a beginner in AWT Java then you know that Frame doesn't close when we press close button of it. So, In last we pressed stop debugging button in Netbeans IDE. If you want to close Frame using Close button, which is see in top right corner of Frame then you should implement code for it. 

Complete Java Code

package awtframe;

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class AWTFrame {

    public AWTFrame()
        Frame f1=new Frame("Welcome to Closing");
        f1.addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent e)
    public static void main(String[] args) {
       AWTFrame at=new AWTFrame();

Here, we have windowClosing ( ) method to close Frame using close button.

Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google