Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

import javax.swing.JFrame;

public class Main {
    /**
     * Causes the given frame to simply go invisible when closed.  Calls
     * {@link JFrame#setDefaultCloseOperation(int)} with <tt>DO_NOTHING_ON_CLOSE</tt>,
     * then adds a {@link WindowListener} that calls {@link JFrame#setVisible(boolean)}
     * with false in {@link WindowListener#windowClosing(WindowEvent)}
     * @param frame the JFrame to make go invisible on close
     */
    public static void goInvisibleOnClose(final JFrame frame) {
        frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                frame.setVisible(false);
            }
        });
    }
}