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:MyFrame.java

public MyFrame() {
    field1 = new JTextField(10);
    getContentPane().add("Center", field1);
    addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent e) {
            field1.requestFocus();/*ww w. j a  v a2 s  .c  om*/
        }
    });
    pack();
    setVisible(true);
}

From source file:Main.java

public Main() {
    setSize(300, 300);//from ww  w  .  j a  va 2s . c o m
    setTitle("Window Listener");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    this.addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent e) {
            System.out.println("Window Opened Event");
        }

        public void windowClosing(WindowEvent e) {
            System.out.println("Window Closing Event");
        }

        public void windowClosed(WindowEvent e) {
            System.out.println("Window Close Event");
        }

        public void windowIconified(WindowEvent e) {
            System.out.println("Window Iconified Event");
        }

        public void windowDeiconified(WindowEvent e) {
            System.out.println("Window Deiconified Event");
        }

        public void windowActivated(WindowEvent e) {
            System.out.println("Window Activated Event");
        }

        public void windowDeactivated(WindowEvent e) {
            System.out.println("Window Deactivated Event");
        }

        public void windowStateChanged(WindowEvent e) {
            System.out.println("Window State Changed Event");
        }

        public void windowGainedFocus(WindowEvent e) {
            System.out.println("Window Gained Focus Event");
        }

        public void windowLostFocus(WindowEvent e) {
            System.out.println("Window Lost Focus Event");
        }
    });
}

From source file:Main.java

public static void activateWindowClosingButton(JFrame frame) {
    frame.addWindowListener(new WindowAdapter() {
        @Override//  w ww .jav  a2 s .c  o  m
        public void windowClosing(WindowEvent evnt) {
            evnt.getWindow().setVisible(false);
            evnt.getWindow().dispose();
        }
    });
}

From source file:Main.java

public static void activateWindowClosingAndSystemExitButton(JFrame frame) {
    frame.addWindowListener(new WindowAdapter() {
        @Override//from  w  w  w .ja  v a2 s . c  o m
        public void windowClosing(WindowEvent evnt) {
            evnt.getWindow().setVisible(false);
            evnt.getWindow().dispose();
            System.exit(0);
        }
    });
}

From source file:au.org.ala.delta.intkey.ui.IntKeyDialogController.java

public static boolean registerDialog(final IntkeyDialog dialog) {
    synchronized (DIALOGS) {
        if (!DIALOGS.contains(dialog)) {
            DIALOGS.add(dialog);//from   ww  w  . j ava  2  s.c o m

            dialog.addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosed(WindowEvent e) {
                    unregisterDialog(dialog);
                }

                @Override
                public void windowActivated(WindowEvent e) {
                    if (!DIALOGS.contains(dialog)) {
                        DIALOGS.add(dialog);
                    }
                }

            });

            return true;
        }
    }
    return false;
}

From source file:ToolbarFrame1.java

public ToolbarFrame1() {
    super("Toolbar Example (AWT)");
    setSize(450, 250);// w  ww  . j a  v a2  s  .  c  om
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    ActionListener printListener = new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            System.out.println(ae.getActionCommand());
        }
    };

    Panel toolbar = new Panel();
    toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));

    cutButton = new Button("Cut");
    cutButton.addActionListener(printListener);
    toolbar.add(cutButton);

    copyButton = new Button("Copy");
    copyButton.addActionListener(printListener);
    toolbar.add(copyButton);

    pasteButton = new Button("Paste");
    pasteButton.addActionListener(printListener);
    toolbar.add(pasteButton);

    add(toolbar, BorderLayout.NORTH);
}

From source file:CircleLayoutTest.java

public CircleLayoutTest() {
    setTitle("CircleLayoutTest");
    setSize(300, 300);/*ww  w . j  av  a  2  s.  c o m*/
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    getContentPane().setLayout(new CircleLayout());
    getContentPane().add(new Button("3"));
    getContentPane().add(new Button("4"));
    getContentPane().add(new Button("5"));
    getContentPane().add(new Button("6"));
    getContentPane().add(new Button("7"));
    getContentPane().add(new Button("8"));
    getContentPane().add(new Button("9"));
    getContentPane().add(new Button("10"));
    getContentPane().add(new Button("11"));
    getContentPane().add(new Button("12"));
    getContentPane().add(new Button("1"));
    getContentPane().add(new Button("2"));
}

From source file:Main.java

public Main() {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel() {
        @Override/*from  w  ww.jav  a2  s.c  o  m*/
        public Dimension getPreferredSize() {
            return new Dimension(300, 300);
        }
    };
    frame.add(panel);
    frame.addWindowStateListener(new WindowAdapter() {
        @Override
        public void windowStateChanged(WindowEvent we) {
            super.windowStateChanged(we);
            if (we.getNewState() == Frame.ICONIFIED) {
                System.out.println("Here");
            }
        }
    });
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public Main() throws HeadlessException {
    setBounds(10, 10, 600, 400);/*  w w  w  . j  av a2  s .  c  om*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setLayout(new BorderLayout());
    add(createDesktop(), BorderLayout.CENTER);
    addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent e) {
            internalFrame.setVisible(true);
        }
    });
    setVisible(true);
}

From source file:Main.java

private WindowAdapter getWindowAdapter() {
    return new WindowAdapter() {
        @Override// www. java 2 s. co m
        public void windowClosing(WindowEvent we) {
            super.windowClosing(we);
            JOptionPane.showMessageDialog(frame, "Cant Exit");
        }

        @Override
        public void windowIconified(WindowEvent we) {
            frame.setState(JFrame.NORMAL);
            JOptionPane.showMessageDialog(frame, "Cant Minimize");
        }
    };
}