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

public static void main(String[] a) {
    JComboBox cbColor = new JComboBox();
    int[] values = new int[] { 0, 128, 192, 255 };
    for (int r = 0; r < values.length; r++)
        for (int g = 0; g < values.length; g++)
            for (int b = 0; b < values.length; b++) {
                Color c = new Color(values[r], values[g], values[b]);
                cbColor.addItem(c);/*from w  ww  .j  av  a 2s . c o m*/
            }
    cbColor.setRenderer(new ColorComboRenderer());

    JFrame f = new JFrame();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    f.getContentPane().add(cbColor);
    f.pack();
    f.setSize(new Dimension(300, 80));
    f.show();

}

From source file:CheckBoxMnemonic.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//from   w  w  w  . j  a va 2s .com
        }
    });
    f.getContentPane().add(new CheckBoxMnemonic());
    f.pack();
    f.setSize(new Dimension(300, 200));
    f.show();

}

From source file:FilledGeneralPath.java

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

From source file:FontList.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//from   w w  w.ja v a  2  s  .  c  o  m
        }
    });
    f.setContentPane(new FontList());
    f.setSize(300, 300);
    f.setVisible(true);
}

From source file:UndoExample1.java

public static void main(String[] args) {
    try {//w w w .j a  v a  2s  .  c o  m
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    JFrame f = new UndoExample1();
    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:EditorPaneExample1.java

public static void main(String[] args) {
    try {/*w w  w .  j av  a  2 s .co m*/
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    JFrame f = new EditorPaneExample1();

    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);
        }
    });
    f.setSize(500, 400);
    f.setVisible(true);
}

From source file:GeneralPathDemo.java

public static void main(String s[]) {

    JFrame f = new JFrame("Odd Shape");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//from   www .  j av  a2s .c om
        }
    });

    f.getContentPane().add(new GeneralPathDemo());
    f.setSize(new Dimension(350, 200));
    f.setVisible(true);
}

From source file:TextLayoutDemo.java

public static void main(String[] args) {
    JFrame frame = new TextLayoutDemo();
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//from www . j  a v  a 2s  .c o m
        }
    });

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

From source file:EventQueuePanel.java

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

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

    frame.show();
}

From source file:ShowComponent.java

public static void main(String[] args) {
    // Process the command line to get the components to display
    Vector components = getComponentsFromArgs(args);

    // Create a frame (a window) to display them in
    JFrame frame = new JFrame("ShowComponent");

    // Handle window close requests by exiting the VM
    frame.addWindowListener(new WindowAdapter() { // Anonymous inner class
        public void windowClosing(WindowEvent e) {
            System.exit(0);//from www.j  a va 2  s.co m
        }
    });

    // Set up a menu system that allows the user to select the
    // look-and-feel of the component from a list of installed PLAFs
    JMenuBar menubar = new JMenuBar(); // Create a menubar
    frame.setJMenuBar(menubar); // Tell the frame to display it
    JMenu plafmenu = createPlafMenu(frame); // Create a menu
    menubar.add(plafmenu); // Add the menu to the menubar

    // Create a JTabbedPane to display each of the components
    JTabbedPane pane = new JTabbedPane();

    // Now add each component as a tab of the tabbed pane
    // Use the unqualified component classname as the tab text
    for (int i = 0; i < components.size(); i++) {
        Component c = (Component) components.elementAt(i);
        String classname = c.getClass().getName();
        String tabname = classname.substring(classname.lastIndexOf('.') + 1);
        pane.addTab(tabname, c);
    }

    // Add the tabbed pane to the frame. Note the call to getContentPane()
    // This is required for JFrame, but not for most Swing components
    frame.getContentPane().add(pane);

    // Set the frame size and pop it up
    frame.pack(); // Make frame as big as its kids need
    frame.setVisible(true); // Make the frame visible on the screen

    // The main() method exits now but the Java VM keeps running because
    // all AWT programs automatically start an event-handling thread.
}