Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class Main extends JFrame {
    public Main() {
        setSize(200, 200);
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent evt) {
                Object[] options = { "Quit, My Computing Fellow", "No, I want to Work more" };

                int answer = JOptionPane.showOptionDialog(Main.this, "What would you like to do? ", "Quit:Continue",
                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
                if (answer == JOptionPane.YES_OPTION) {
                    System.exit(0);
                }
            }
        });
    }

    public static void main(String st[]) {
        Main mf = new Main();
        mf.setVisible(true);
    }
}