List of usage examples for java.awt.event WindowAdapter WindowAdapter
WindowAdapter
From source file:Main.java
public static void main(String... args) { JFrame frame = new JFrame(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { int result = JOptionPane.showConfirmDialog(frame, "Do you want to Exit ?", "Exit Confirmation : ", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); else if (result == JOptionPane.NO_OPTION) frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); }/* w w w . j a va2s .com*/ }); frame.setSize(300, 300); frame.setVisible(true); }
From source file:FrameClose2.java
public static void main(String[] args) { JFrame mainFrame = new JFrame(); // Exit app when frame is closed. mainFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent ev) { System.exit(0);/*from w w w.ja v a 2s . c o m*/ } }); mainFrame.setSize(320, 240); mainFrame.setVisible(true); }
From source file:WindowAdapterTest.java
public static void main(String args[]) { JFrame frame = new JFrame("Window Listener"); WindowListener listener = new WindowAdapter() { public void windowClosing(WindowEvent w) { System.exit(0);//from ww w . j a v a2s . c o m } }; frame.addWindowListener(listener); frame.setSize(300, 300); frame.show(); }
From source file:Main.java
public static void main(String[] a) { JDialog f = new JDialog(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);//from w ww . j a va 2 s.c om } }); JButton btOK = new JButton("Press Enter to click me, I am the default."); btOK.setToolTipText("Save and exit"); f.getRootPane().setDefaultButton(btOK); JPanel p = new JPanel(); p.add(btOK); p.add(new JButton("I am NOT the default.")); f.getContentPane().add(p); f.pack(); f.setSize(new Dimension(300, 200)); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { Main frame = new Main(); frame.setSize(new Dimension(200, 200)); frame.add(new Button("Hello World")); frame.addWindowListener(new WindowAdapter() { @Override/*from w w w .j a v a 2s. c om*/ public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.setVisible(true); }
From source file:DefaultButton.java
public static void main(String[] a) { JDialog f = new JDialog(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);//from www. ja v a 2s.com } }); JButton btOK = new JButton("Press Enter to click me, I am the default."); btOK.setToolTipText("Save and exit"); f.getRootPane().setDefaultButton(btOK); JPanel p = new JPanel(); p.add(btOK); p.add(new JButton("I am NOT the default.")); f.getContentPane().add(p); f.pack(); f.setSize(new Dimension(300, 200)); f.show(); }
From source file:SVGCanvasDemo.java
public static void main(String args[]) { JFrame frame = new JFrame("JSVGCanvas Demo"); frame.setSize(400, 400);//from w w w.j a v a2s .c o m frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent ev) { System.exit(0); } }); new SVGCanvasDemo(frame); }
From source file:NotHelloWorldPanel.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setTitle("NotHelloWorld"); frame.setSize(300, 200);/* w ww.ja va 2 s .co m*/ frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); Container contentPane = frame.getContentPane(); contentPane.add(new NotHelloWorldPanel()); 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);/*from w w w. ja v a 2 s.c o 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:SimpleGridBag.java
public static void main(String[] args) { JFrame f = new JFrame(); JPanel p = new JPanel(); p.setLayout(new GridBagLayout()); p.add(new JButton("Java")); p.add(new JButton("Source")); p.add(new JButton("and")); p.add(new JButton("Support.")); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);// www.jav a 2 s . c o m } }; f.addWindowListener(wndCloser); f.getContentPane().add(p); f.setSize(600, 200); f.show(); }