List of usage examples for javax.swing JFrame addWindowListener
public synchronized void addWindowListener(WindowListener l)
From source file:org.jfree.chart.demo.MemoryUsageDemo.java
public static void main(String args[]) { JFrame jframe = new JFrame("Memory Usage Demo"); MemoryUsageDemo memoryusagedemo = new MemoryUsageDemo(30000); jframe.getContentPane().add(memoryusagedemo, "Center"); jframe.setBounds(200, 120, 600, 280); jframe.setVisible(true);/*from w w w .j av a2s . c o m*/ (memoryusagedemo.new DataGenerator(100)).start(); jframe.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowevent) { System.exit(0); } }); }
From source file:EditorDropTarget.java
public static void main(String[] args) { try {/*ww w. j a va 2s . co m*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } final JFrame f = new JFrame("JEditor Pane Drop Target Example 1"); JEditorPane pane = new JEditorPane(); // Add a drop target to the JEditorPane EditorDropTarget target = new EditorDropTarget(pane); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.getContentPane().add(new JScrollPane(pane), BorderLayout.CENTER); f.setSize(500, 400); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame frm = new JFrame("Main"); Image im = Toolkit.getDefaultToolkit().getImage("c:\\icons\\icon1.png"); TrayIcon tri = new TrayIcon(im); tri.addActionListener(e -> {//from w w w. j av a 2 s.c o m frm.setVisible(true); try { SystemTray.getSystemTray().remove(tri); } catch (Exception ex) { ex.printStackTrace(); } }); frm.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { try { SystemTray.getSystemTray().add(tri); } catch (Exception ex) { ex.printStackTrace(); } frm.setVisible(false); } }); frm.setSize(100, 100); frm.setVisible(true); }
From source file:GraphPaperTest.java
public static void main(String[] args) { JFrame f = new JFrame("GraphPaperTest"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);/* w ww .j ava2s . co m*/ } }); f.getContentPane().add(new GraphPaperTest(), BorderLayout.CENTER); f.pack(); f.setVisible(true); }
From source file:UndoExample5.java
public static void main(String[] args) { try {/*from w w w . j a v a2 s .c o m*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new UndoExample5(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setSize(250, 300); f.setVisible(true); // Create and show a frame monitoring undoable edits JFrame undoMonitor = new JFrame("Undo Monitor"); final JTextArea textArea = new JTextArea(); textArea.setEditable(false); undoMonitor.getContentPane().add(new JScrollPane(textArea)); undoMonitor.setBounds(f.getLocation().x + f.getSize().width, f.getLocation().y, 400, 200); undoMonitor.setVisible(true); pane.getDocument().addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { UndoableEdit edit = evt.getEdit(); textArea.append(edit.getPresentationName() + "(" + edit.toString() + ")\n"); } }); // Create and show a frame monitoring document edits JFrame editMonitor = new JFrame("Edit Monitor"); final JTextArea textArea2 = new JTextArea(); textArea2.setEditable(false); editMonitor.getContentPane().add(new JScrollPane(textArea2)); editMonitor.setBounds(undoMonitor.getLocation().x, undoMonitor.getLocation().y + undoMonitor.getSize().height, 400, 200); editMonitor.setVisible(true); pane.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent evt) { textArea2.append("Attribute change\n"); } public void insertUpdate(DocumentEvent evt) { textArea2.append("Text insertion\n"); } public void removeUpdate(DocumentEvent evt) { textArea2.append("Text removal\n"); } }); }
From source file:EditorPaneExample10.java
public static void main(String[] args) { try {//from w w w. ja v a 2 s. c o m UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new EditorPaneExample10(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setSize(500, 400); f.setVisible(true); }
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);//from www . j a va 2 s . com } }; f.addWindowListener(wndCloser); f.getContentPane().add(p); f.setSize(600, 200); f.show(); }
From source file:edu.mit.fss.tutorial.part4.ElementGUI.java
/** * The main method./* www.j a va2 s . co m*/ * * @param args the arguments * @throws RTIexception the RTI exception */ public static void main(String[] args) throws RTIexception { // Configure the logger and set it to display info messages. BasicConfigurator.configure(); logger.setLevel(Level.INFO); // Use an input dialog to request the element's name. String name = null; while (name == null || name.isEmpty()) { name = JOptionPane.showInputDialog("Enter element name:"); } // Create a MobileElement object instance. The "final" keyword allows // it to be referenced in the GUI thread below. final MobileElement element = new MobileElement(name, new Vector3D(0, 0, 0)); // Create an OnlineTutorialFederate object instance. The "final" // keyword allows it to be referenced in the GUI thread below. final OnlineTutorialFederate fed = new OnlineTutorialFederate(element); // Create the graphical user interface using the Event Dispatch Thread. try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { // Create a new ControlPanel object instance. ControlPanel controlPanel = new ControlPanel(); // Bind it to the element above. controlPanel.setBoundElement(element); // Add the control panel as an object change listener. fed.addObjectChangeListener(controlPanel); // Create a new frame to display the panel. Add the panel // as the content, pack it, and make it visible. JFrame frame = new JFrame(); frame.setContentPane(controlPanel); frame.pack(); frame.setVisible(true); // Add a new WindowAdapter object instance to exit the // federate when the window is closing. frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { fed.exit(); } }); } }); } catch (InvocationTargetException | InterruptedException e) { logger.error(e); } // Execute the federate. fed.execute(0, Long.MAX_VALUE, 1000); }
From source file:AccessibleScrollDemo.java
public static void main(String s[]) { JFrame frame = new JFrame("AccessibleScrollDemo"); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);// w ww . jav a 2s.c om } }); frame.setContentPane(new AccessibleScrollDemo()); frame.pack(); frame.setVisible(true); }
From source file:URLMonitorPanel.java
public static void main(String[] args) throws Exception { JFrame frame = new JFrame("URL Monitor"); Container c = frame.getContentPane(); c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS)); Timer t = new Timer(); String[] u = new String[] { "http://www.java2s.com", "http://www.java2s.com" }; for (int i = 0; i < u.length; i++) { c.add(new URLMonitorPanel(u[i], t)); }/*from ww w . j ava2s .c o m*/ frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); frame.pack(); frame.show(); }