AWT Frame close using close Button

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.
AWT Frame close using close Button AWT Frame close using close Button Reviewed by Jacob Lefore on December 12, 2015 Rating: 5

No comments