Set default close operation for JFrame - Java Swing

Java examples for Swing:JFrame

Description

Set default close operation for JFrame

Demo Code

     /*from   ww w.j a  v a 2 s  . c om*/

import java.awt.*;
import javax.swing.*;

public class Main extends JFrame{
     public Main() {
          super("Hello World");
          getContentPane().setLayout(new FlowLayout());
          JLabel label = new JLabel("Welcome to Swing");
          getContentPane().add(label);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          
          setSize(200, 200);
          setVisible(true);
     }

     public static void main(String[] args) {
          Main app = new Main();

     }

}

Related Tutorials