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

/**
 * A main() method so FileLister can be run standalone. Parse command line
 * arguments and create the FileLister object. If an extension is specified,
 * create a FilenameFilter for it. If no directory is specified, use the
 * current directory./*from   w  w  w.j a  va2s  .com*/
 */
public static void main(String args[]) throws IOException {
    FileLister f;
    FilenameFilter filter = null; // The filter, if any
    String directory = null; // The specified dir, or the current dir

    // Loop through args array, parsing arguments
    for (int i = 0; i < args.length; i++) {
        if (args[i].equals("-e")) {
            if (++i >= args.length)
                usage();
            final String suffix = args[i]; // final for anon. class below

            // This class is a simple FilenameFilter. It defines the
            // accept() method required to determine whether a specified
            // file should be listed. A file will be listed if its name
            // ends with the specified extension, or if it is a directory.
            filter = new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    if (name.endsWith(suffix))
                        return true;
                    else
                        return (new File(dir, name)).isDirectory();
                }
            };
        } else {
            if (directory != null)
                usage(); // If already specified, fail.
            else
                directory = args[i];
        }
    }

    // if no directory specified, use the current directory
    if (directory == null)
        directory = System.getProperty("user.dir");
    // Create the FileLister object, with directory and filter specified.
    f = new FileLister(directory, filter);
    // Arrange for the application to exit when the window is closed
    f.addWindowListener(new WindowAdapter() {
        public void windowClosed(WindowEvent e) {
            System.exit(0);
        }
    });
    // Finally, pop the window up up.
    f.show();
}

From source file:com.codeasylum.stress.ui.Jormungandr.java

public static void main(String... args) {

    boolean init = false;

    try {//from  w  w  w.ja  v a 2  s . c  o m
        new ExtendedTaskLoader();
        init = true;
    } catch (Exception exception) {
        JavaErrorDialog.showJavaErrorDialog(null, null, exception);
    }

    if (init) {

        final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
                "com/codeasylum/stress/api/logging.xml", "com/codeasylum/stress/ui/jormungandr.xml");

        Jormungandr jormungandr = applicationContext.getBean("jormungandr", Jormungandr.class);

        try {
            jormungandr.addWindowListener(new WindowAdapter() {

                @Override
                public void windowClosed(WindowEvent windowEvent) {

                    applicationContext.close();

                }
            });

            jormungandr.init().setVisible(true);
        } catch (Exception exception) {
            JavaErrorDialog.showJavaErrorDialog(jormungandr, jormungandr, exception);
            jormungandr.dispose();
        }
    }
}

From source file:IDlookGetStream.java

public static void main(String[] args) {
    IDlookGetStream id = new IDlookGetStream();

    id.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//from   w w  w .  j  a va 2 s . com
        }
    });

    id.init();
    id.buildGUI();
}

From source file:Main.java

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

    frame.getContentPane().add(new Main(), BorderLayout.CENTER);
    // Finally, set the size of the main window, and pop it up.
    frame.setSize(600, 400);
    frame.setVisible(true);
}

From source file:EventTestPane.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//from w w w.  ja va2s.c  o m
        }
    });

    frame.getContentPane().add(new EventTestPane(), BorderLayout.CENTER);
    // Finally, set the size of the main window, and pop it up.
    frame.setSize(600, 400);
    frame.setVisible(true);
}

From source file:EditorPaneExample10.java

public static void main(String[] args) {
    try {//  w  w w.  j av  a2s .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:Main.java

public static void main() {
    Frame frame = new Frame();
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            Frame frame = (Frame) evt.getSource();
            frame.setVisible(false);//from   w  w  w  .j av a  2 s. c o m
            // frame.dispose();
        }
    });
}

From source file:Main.java

public static void main() {
    Frame frame = new Frame();

    WindowListener listener = new WindowAdapter() {
        public void windowOpened(WindowEvent evt) {
            Frame frame = (Frame) evt.getSource();
            System.out.println(frame.getTitle());
        }//from  w  ww . j ava 2  s . c  o m

        public void windowClosing(WindowEvent evt) {
            Frame frame = (Frame) evt.getSource();

            System.out.println(frame.getTitle());

        }

        public void windowClosed(WindowEvent evt) {
            Frame frame = (Frame) evt.getSource();
            System.out.println(frame.getTitle());
        }
    };

    frame.addWindowListener(listener);
    frame.setVisible(true);
}

From source file:Main.java

public static void main() {

    Frame frame = new Frame();

    WindowStateListener listener = new WindowAdapter() {
        public void windowStateChanged(WindowEvent evt) {
            int oldState = evt.getOldState();
            int newState = evt.getNewState();

            if ((oldState & Frame.ICONIFIED) == 0 && (newState & Frame.ICONIFIED) != 0) {
                System.out.println("Frame was iconized");
            } else if ((oldState & Frame.ICONIFIED) != 0 && (newState & Frame.ICONIFIED) == 0) {
                System.out.println("Frame was deiconized");
            }//from   w  ww  .j a va 2  s . co m

            if ((oldState & Frame.MAXIMIZED_BOTH) == 0 && (newState & Frame.MAXIMIZED_BOTH) != 0) {
                System.out.println("Frame was maximized");
            } else if ((oldState & Frame.MAXIMIZED_BOTH) != 0 && (newState & Frame.MAXIMIZED_BOTH) == 0) {
                System.out.println("Frame was minimized");
            }
        }
    };

    frame.addWindowStateListener(listener);
    frame.setVisible(true);
}

From source file:Main.java

/**
 * create JFrame that has a WindowListener object that was invoked
 * System.exit(0) by pushing close button.
 *///w w  w . j a v  a2s.c o  m
public static JFrame getTestFrame(String title) {
    JFrame f = new JFrame(title);
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    return f;
}