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

public static void main(String args[]) {

    UIManager.put("swing.boldMetal", Boolean.FALSE);
    JFrame f = new JFrame("Hello World Printer");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*from   w  w  w .  jav a  2s . c o m*/
        }
    });
    JButton printButton = new JButton("Print Hello World");
    printButton.addActionListener(new HelloWorldPrinter());
    f.add("Center", printButton);
    f.pack();
    f.setVisible(true);
}

From source file:LineBreakSample.java

public static void main(String[] args) {
    JFrame f = new JFrame("");

    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//  w w w.  ja  v  a 2  s .c o  m
        }
    });

    LineBreakSample controller = new LineBreakSample();
    f.getContentPane().add(controller, "Center");
    f.setSize(new Dimension(400, 250));
    f.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);/*from ww  w . j a  v  a 2s.co  m*/
        }
    });

    f.getContentPane().add(new GraphPaperTest(), BorderLayout.CENTER);
    f.pack();
    f.setVisible(true);
}

From source file:SimpleClient.java

public static void main(String argv[]) {
    boolean usage = false;

    for (int optind = 0; optind < argv.length; optind++) {
        if (argv[optind].equals("-L")) {
            url.addElement(argv[++optind]);
        } else if (argv[optind].startsWith("-")) {
            usage = true;/*from  w  w w. j  ava  2s  . c o m*/
            break;
        } else {
            usage = true;
            break;
        }
    }

    if (usage || url.size() == 0) {
        System.out.println("Usage: SimpleClient -L url");
        System.out.println("   where url is protocol://username:password@hostname/");
        System.exit(1);
    }

    try {
        // Set up our Mailcap entries.  This will allow the JAF
        // to locate our viewers.
        File capfile = new File("simple.mailcap");
        if (!capfile.isFile()) {
            System.out.println("Cannot locate the \"simple.mailcap\" file.");
            System.exit(1);
        }

        CommandMap.setDefaultCommandMap(new MailcapCommandMap(new FileInputStream(capfile)));

        JFrame frame = new JFrame("Simple JavaMail Client");
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        //frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        // Get a Store object
        SimpleAuthenticator auth = new SimpleAuthenticator(frame);
        Session session = Session.getDefaultInstance(System.getProperties(), auth);
        //session.setDebug(true);

        DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");

        // create a node for each store we have
        for (Enumeration e = url.elements(); e.hasMoreElements();) {
            String urlstring = (String) e.nextElement();
            URLName urln = new URLName(urlstring);
            Store store = session.getStore(urln);

            StoreTreeNode storenode = new StoreTreeNode(store);
            root.add(storenode);
        }

        DefaultTreeModel treeModel = new DefaultTreeModel(root);
        JTree tree = new JTree(treeModel);
        tree.addTreeSelectionListener(new TreePress());

        /* Put the Tree in a scroller. */
        JScrollPane sp = new JScrollPane();
        sp.setPreferredSize(new Dimension(250, 300));
        sp.getViewport().add(tree);

        /* Create a double buffered JPanel */
        JPanel sv = new JPanel(new BorderLayout());
        sv.add("Center", sp);

        fv = new FolderViewer(null);

        JSplitPane jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sv, fv);
        jsp.setOneTouchExpandable(true);
        mv = new MessageViewer();
        JSplitPane jsp2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, jsp, mv);
        jsp2.setOneTouchExpandable(true);

        frame.getContentPane().add(jsp2);
        frame.pack();
        frame.show();

    } catch (Exception ex) {
        System.out.println("SimpletClient caught exception");
        ex.printStackTrace();
        System.exit(1);
    }
}

From source file:PrintUIWindow.java

public static void main(String args[]) {
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    JFrame f = new JFrame("Print UI Example");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//www.  j av a 2s  .  c om
        }
    });
    JTextArea text = new JTextArea(50, 20);
    for (int i = 1; i <= 50; i++) {
        text.append("Line " + i + "\n");
    }
    JScrollPane pane = new JScrollPane(text);
    pane.setPreferredSize(new Dimension(250, 200));
    f.add("Center", pane);
    JButton printButton = new JButton("Print This Window");
    printButton.addActionListener(new PrintUIWindow(f));
    f.add("South", printButton);
    f.pack();
    f.setVisible(true);
}

From source file:EditorPaneExample3.java

public static void main(String[] args) {
    try {//from 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 EditorPaneExample3();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);
        }
    });
    f.setSize(500, 400);
    f.setVisible(true);
}

From source file:HitTestSample.java

public static void main(String[] args) {

    JFrame f = new JFrame("HitTestSample");
    HitTestSample demo = new HitTestSample();
    f.getContentPane().add(demo, "Center");

    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//from w  w  w  .ja  v a2 s. com
        }
    });

    f.setSize(new Dimension(400, 250));
    f.setVisible(true);
}

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 w w  w. j  a  va2 s  .co m
        }
    });
    frame.getContentPane().add("Center", new TextLayoutPanel());
    frame.pack();
    frame.setSize(new Dimension(400, 300));
    frame.setVisible(true);
}

From source file:com.adito.upgrade.Upgrade.java

/**
 * @param args//ww  w.j  ava2 s  .  co  m
 * @throws Exception on any error
 */
public static void main(String[] args) throws Exception {

    boolean gui = System.getProperty("os.name").toLowerCase().startsWith("windows")
            || System.getenv("DISPLAY") != null;

    if (args.length == 2 || !gui) {
        Upgrader upgrader = new CommandLineUpgrader(args);
        upgrader.upgrade();
    } else {
        JFrame f = new JFrame("0.1.16 to 0.2.5+ Upgrader");
        final Upgrader upgrader = new GUIUpgrader();
        f.setIconImage(new ImageIcon(Upgrade.class.getResource("upgrader-32x32.png")).getImage());
        f.getContentPane().setLayout(new BorderLayout());
        f.getContentPane().add((JPanel) upgrader, BorderLayout.CENTER);
        f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        JPanel bp = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        final JButton start = new JButton("Start");
        ;
        final JButton close = new JButton("Close");
        start.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    start.setEnabled(false);
                    close.setEnabled(false);
                    upgrader.upgrade();
                } catch (Exception ex) {
                    upgrader.error("Failed to upgrade.", ex);
                } finally {
                    close.setEnabled(true);
                }
            }
        });
        close.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (close.isEnabled())
                    System.exit(0);
            }
        });
        bp.add(start);
        bp.add(close);
        f.getContentPane().add(bp, BorderLayout.SOUTH);
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent evt) {
                if (close.isEnabled())
                    System.exit(0);
            }
        });
        f.setSize(new Dimension(480, 460));
        UIUtil.positionComponent(SwingConstants.CENTER, f);
        f.setVisible(true);
    }
}

From source file:edu.mit.fss.tutorial.part4.ElementGUI.java

/**
 * The main method./*  w  w w.j  a  v  a2s . 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);
}