Example usage for java.awt.event WindowAdapter WindowAdapter

List of usage examples for java.awt.event WindowAdapter WindowAdapter

Introduction

In this page you can find the example usage for java.awt.event WindowAdapter WindowAdapter.

Prototype

WindowAdapter

Source Link

Usage

From source file:Main.java

/**
 * Attaches a {@link WindowListener} to the given Window so it is disposed
 * when the close button is hit. Some windows do not respond to the
 * DISPOSE_ON_CLOSE operation, so this is better than using that.
 *///from w ww  . ja v  a 2  s  . c o m
public static void attachDisposeOnClose(final Window w) {
    w.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            w.setVisible(false);
            w.dispose();
        }
    });
}

From source file:Main.java

public static void packLater(final Window win, final Component parent) {
    win.pack();//from   w  w w  . ja  v a2s.co m
    win.setLocationRelativeTo(parent);
    win.addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            win.pack();
            win.setLocationRelativeTo(parent);
        }
    });
}

From source file:Demo3D.java

/**
 * Main of the Demo program. Take the graphic environment of the
 * workstation.//from w w w  .j  a v a  2  s . co  m
 */
public static void main(String args[]) {
    JFrame jFrameDemo = new Demo3D();

    // To be sure to stop the application when the frame is closed.
    WindowListener winListener = new WindowAdapter() {
        public void windowClosing(WindowEvent event) {
            System.exit(0);
        }
    };

    jFrameDemo.addWindowListener(winListener);

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    screenwidth = (int) screenSize.getWidth();
    screenheight = (int) screenSize.getHeight();
    jFrameDemo.setSize(screenwidth, screenheight);

    // Turn on the visibility of the frame.
    jFrameDemo.setVisible(true);

    fpsThread.start();
}

From source file:Main.java

/**
 * 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
 *///from w  w w .j  a va  2  s  . c om
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);
        }
    });
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override//from   w w w  .  java  2  s.co  m
        public void windowClosing(WindowEvent e) {
            System.out.println("closing...");
        }
    });
}

From source file:CloseFrameAction.java

public CloseFrameAction() {
    setTitle("CloseableFrame");
    setSize(300, 200);// w w  w. jav  a2  s.c  om
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
}

From source file:Main.java

public Main() {
    setTitle("CenteredFrame");
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*  ww w  .  java  2 s.co m*/
        }
    });
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension screenSize = tk.getScreenSize();
    int screenHeight = screenSize.height;
    int screenWidth = screenSize.width;
    setSize(screenWidth / 2, screenHeight / 2);
    setLocation(screenWidth / 4, screenHeight / 4);
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent e) {
        }/*www. j av  a 2s .  c  o m*/

        public void windowClosing(WindowEvent e) {
            if (JOptionPane.showConfirmDialog(null, "Are you sure ?") == JOptionPane.YES_OPTION) {
                setVisible(false);
                dispose();
            }
        }
    });
    pack();
    setVisible(true);
}

From source file:CenteredFrame.java

public CenteredFrame() {
    setTitle("CenteredFrame");
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//from ww w  .j ava  2 s .co m
        }
    });
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension screenSize = tk.getScreenSize();
    int screenHeight = screenSize.height;
    int screenWidth = screenSize.width;
    setSize(screenWidth / 2, screenHeight / 2);
    setLocation(screenWidth / 4, screenHeight / 4);
}

From source file:Main.java

public Main() {
    setSize(200, 200);//from  w  ww.j ava 2s.c om
    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);
            }
        }
    });
}