FrameClose2.java Source code

Java tutorial

Introduction

Here is the source code for FrameClose2.java

Source

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

import javax.swing.JFrame;

public class FrameClose2 {
    public static void main(String[] args) {
        JFrame mainFrame = new JFrame();

        // Exit app when frame is closed.
        mainFrame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent ev) {
                System.exit(0);
            }
        });

        mainFrame.setSize(320, 240);
        mainFrame.setVisible(true);
    }
}