Example usage for javax.swing JFrame addWindowListener

List of usage examples for javax.swing JFrame addWindowListener

Introduction

In this page you can find the example usage for javax.swing JFrame addWindowListener.

Prototype

public synchronized void addWindowListener(WindowListener l) 

Source Link

Document

Adds the specified window listener to receive window events from this window.

Usage

From source file:XMLTreeView.java

public static void main(String args[]) {
    JFrame frame = new JFrame("XMLTreeView: [ games.xml ]");
    frame.setSize(400, 400);//from w w  w  .j av  a  2 s .c  o  m

    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent ev) {
            System.exit(0);
        }
    });
    file = "games.xml";
    new XMLTreeView(frame);
}

From source file:TextLayoutPanel.java

public static void main(String arg[]) {
    JFrame frame = new JFrame();
    frame.setBackground(Color.white);
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*from  ww w  . ja v a 2s. c o m*/
        }
    });
    frame.getContentPane().add("Center", new TextLayoutPanel());
    frame.pack();
    frame.setSize(new Dimension(400, 300));
    frame.setVisible(true);
}

From source file:BufferedDraw.java

public static void main(String s[]) {

    JFrame f = new JFrame("BufferedShapeMover");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*from  w  w  w  . j a v a2 s  . co m*/
        }
    });
    f.getContentPane().setLayout(new BorderLayout());
    f.getContentPane().add(new BufferedDraw(), "Center");

    f.pack();
    f.setSize(new Dimension(550, 250));
    f.show();
}

From source file:ImageOps.java

public static void main(String s[]) {
    JFrame f = new JFrame("ImageOps");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*from   w  ww  . j a va 2s  .c o m*/
        }
    });
    JApplet applet = new ImageOps();
    f.getContentPane().add("Center", applet);
    applet.init();
    f.pack();
    f.setSize(new Dimension(550, 550));
    f.show();
}

From source file:BorderDemo.java

public static void main(String[] args) {
    JFrame frame = new BorderDemo();
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*from  w  w  w.j a va  2  s. com*/
        }
    });

    frame.pack();
    frame.setVisible(true);
}

From source file:ColorAction.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setTitle("SeparateGUITest");
    frame.setSize(300, 200);/*from   ww  w .ja  v  a  2s. co  m*/
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    JPanel panel = new JPanel();

    Action blueAction = new ColorAction("Blue", new ImageIcon("blue-ball.gif"), Color.blue, panel);
    Action yellowAction = new ColorAction("Yellow", new ImageIcon("yellow-ball.gif"), Color.yellow, panel);
    Action redAction = new ColorAction("Red", new ImageIcon("red-ball.gif"), Color.red, panel);

    panel.add(new JButton(yellowAction));
    panel.add(new JButton(blueAction));
    panel.add(new JButton(redAction));

    panel.registerKeyboardAction(yellowAction, KeyStroke.getKeyStroke(KeyEvent.VK_Y, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);
    panel.registerKeyboardAction(blueAction, KeyStroke.getKeyStroke(KeyEvent.VK_B, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);
    panel.registerKeyboardAction(redAction, KeyStroke.getKeyStroke(KeyEvent.VK_R, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);

    Container contentPane = frame.getContentPane();
    contentPane.add(panel);

    JMenu m = new JMenu("Color");
    m.add(yellowAction);
    m.add(blueAction);
    m.add(redAction);
    JMenuBar mbar = new JMenuBar();
    mbar.add(m);
    frame.setJMenuBar(mbar);

    frame.show();
}

From source file:Main.java

public static void main(String[] args) {
    JPanel panel = new JPanel();
    panel.add(new JTextField(10));
    panel.add(new JButton("button"));
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(panel);//w  w w .j a  v a  2 s.co  m
    frame.pack();
    frame.setVisible(true);

    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowIconified(WindowEvent wEvt) {
            ((JFrame) wEvt.getSource()).dispose();
        }

        @Override
        public void windowDeactivated(WindowEvent wEvt) {
            ((JFrame) wEvt.getSource()).dispose();
        }
    });
}

From source file:SwingSuspendResume.java

public static void main(String[] args) {
    SwingSuspendResume vsr = new SwingSuspendResume();
    Thread t = new Thread(vsr);
    t.start();/*from   ww  w.  j a  v a 2s  .c o m*/

    JFrame f = new JFrame();
    f.setContentPane(vsr);
    f.setSize(320, 200);
    f.setVisible(true);
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
}

From source file:CustomIconDemo.java

public static void main(String[] args) {
    JFrame frame = new JFrame("CustomIconDemo");
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);// w  ww  .  j  a va 2s  . c o  m
        }
    });

    frame.getContentPane().add(new CustomIconDemo(), BorderLayout.CENTER);
    frame.pack();
    frame.setVisible(true);
}

From source file:MouseDragActionPanel.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setTitle("MouseTest");
    frame.setSize(300, 200);/*from  w w  w . j ava2 s .  c o  m*/
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    Container contentPane = frame.getContentPane();
    contentPane.add(new MouseDragActionPanel());

    frame.show();
}