JFrame.EXIT_ON_CLOSE and DISPOSE_ON_CLOSE

DISPOSE_ON_CLOSE   :   This method is used to close the current frame. But doesn’t terminate the application.

EXIT_ON_CLOSE            :   This method is used to close the all frame and finally to terminate the application

Program

sdfd

 

 

 

Program Source

import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.FlowLayout;

class Frame extends JFrame {
   
    Frame()
    {
        setTitle("EXIT_ON_CLOSE");
        setLayout(new FlowLayout());
        add(new JLabel("Close All Frame"));
        setSize(700, 200);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        subFrame();
    }
    
    void subFrame()
    {
        JFrame sub = new JFrame();
        sub.setTitle("DISPOSE_ON_CLOSE");
        sub.setLayout(new FlowLayout());
        sub.add(new JLabel("Close This Frame"));
        sub.setSize(700, 200);
        sub.setVisible(true);
        sub.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }
}

public class Javaapp {
   
    public static void main(String[] args) {
        
       Frame fr = new Frame();
    }
}

Leave a Comment