Example usage for java.awt.event WindowListener WindowListener

List of usage examples for java.awt.event WindowListener WindowListener

Introduction

In this page you can find the example usage for java.awt.event WindowListener WindowListener.

Prototype

WindowListener

Source Link

Usage

From source file:WindowTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Window Listener");
    WindowListener listener = new WindowListener() {
        public void windowActivated(WindowEvent w) {
            System.out.println(w);
        }/*w  w  w. j av  a 2  s.  c  om*/

        public void windowClosed(WindowEvent w) {
            System.out.println(w);
        }

        public void windowClosing(WindowEvent w) {
            System.out.println(w);
            System.exit(0);
        }

        public void windowDeactivated(WindowEvent w) {
            System.out.println(w);
        }

        public void windowDeiconified(WindowEvent w) {
            System.out.println(w);
        }

        public void windowIconified(WindowEvent w) {
            System.out.println(w);
        }

        public void windowOpened(WindowEvent w) {
            System.out.println(w);
        }
    };
    frame.addWindowListener(listener);
    frame.setSize(300, 300);
    frame.show();
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    JFrame frame = new JFrame();
    frame.addWindowListener(new WindowListener() {
        @Override//from  w ww.jav  a 2 s  . c o  m
        public void windowOpened(WindowEvent e) {
            System.out.println("JFrame has  been  made visible first  time");
        }

        @Override
        public void windowClosing(WindowEvent e) {
            System.out.println("JFrame is closing.");
        }

        @Override
        public void windowClosed(WindowEvent e) {
            System.out.println("JFrame is closed.");
        }

        @Override
        public void windowIconified(WindowEvent e) {
            System.out.println("JFrame is  minimized.");
        }

        @Override
        public void windowDeiconified(WindowEvent e) {
            System.out.println("JFrame is restored.");
        }

        @Override
        public void windowActivated(WindowEvent e) {
            System.out.println("JFrame is activated.");
        }

        @Override
        public void windowDeactivated(WindowEvent e) {
            System.out.println("JFrame is deactivated.");
        }
    });

    // Use the WindowAdapter class to intercept only the window closing event
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            System.out.println("JFrame is closing.");
        }
    });

}

From source file:UsingWindowListener.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is the Window Title");
    aWindow.setBounds(50, 100, 300, 300);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    aWindow.addWindowListener(new WindowListener() {
        public void windowIconified(WindowEvent e) {
            System.out.println(e);
        }// w  w  w  .  jav  a 2 s  .c  o  m

        public void windowDeiconified(WindowEvent e) {

        }

        public void windowOpened(WindowEvent e) {
        }

        public void windowClosing(WindowEvent e) {
        }

        public void windowClosed(WindowEvent e) {
        }

        public void windowActivated(WindowEvent e) {
        }

        public void windowDeactivated(WindowEvent e) {
        }

    });

    aWindow.setVisible(true);
}

From source file:com.github.thebigs.foscam.recorder.RecorderGUI.java

public static void main(String[] args) {
    gui = new RecorderGUI();

    gui.setBounds(0, 0, 800, 700);//from  w  w w. ja va 2  s  . com
    gui.setVisible(true);
    gui.addWindowListener(new WindowListener() {
        @Override
        public void windowClosing(WindowEvent arg0) {
            System.out.println("Closing...");
            if (recorder != null) {
                recorder.shutdown();
            }
            System.out.println("Finished.");
            System.exit(0);
        }

        @Override
        public void windowActivated(WindowEvent arg0) {
        }

        @Override
        public void windowClosed(WindowEvent arg0) {
        }

        @Override
        public void windowDeactivated(WindowEvent arg0) {
        }

        @Override
        public void windowDeiconified(WindowEvent arg0) {
        }

        @Override
        public void windowIconified(WindowEvent arg0) {
        }

        @Override
        public void windowOpened(WindowEvent arg0) {
        }
    });
}

From source file:org.gridchem.client.GridChem.java

public static void main(String[] args) {
    Trace.entry();/*from www. j a va  2  s. c  o  m*/

    try {
        setCommandLineOptions();
        parseCommandLine(args);
    } catch (Exception e) {
        System.out.println("Invalid command line option given: " + e.getMessage());
    }

    //JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame();

    // Edited by Shashank & Sandeep @ CCS,UKY April 10 2005
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);
    /*MetalTheme theme = new G03Input.ColorTheme();  
    MetalLookAndFeel.setCurrentTheme(theme);
    try {
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
        SwingUtilities.updateComponentTreeUI(frame);
    } catch(Exception e) {
        System.out.println(e);
    }*/

    // Use the native look and feel since Java's is pretty lame.
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        // Ignore exceptions, which only result in the wrong look and feel.
        System.out.println("GridChem.main: an exception related to the" + " look and feel was ignored.");
    }

    init();

    frame.setTitle("GridChem " + Env.getVersion());
    frame.getContentPane().add(oc);
    frame.addWindowListener(new WindowListener() {

        public void windowActivated(WindowEvent arg0) {
        }

        public void windowClosed(WindowEvent arg0) {
        }

        public void windowClosing(WindowEvent arg0) {
            if (Settings.authenticated) {
                GMS3.logout();
            }
        }

        public void windowDeactivated(WindowEvent arg0) {
        }

        public void windowDeiconified(WindowEvent arg0) {
        }

        public void windowIconified(WindowEvent arg0) {
        }

        public void windowOpened(WindowEvent arg0) {
        }

    });
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();

    // Centering the frame on the screen
    Toolkit kit = frame.getToolkit();
    Dimension screenSize = kit.getScreenSize();
    int screenWidth = screenSize.width;
    int screenHeight = screenSize.height;
    Dimension windowSize = frame.getSize();
    int windowWidth = windowSize.width;
    int windowHeight = windowSize.height;
    int upperLeftX = (screenWidth - windowWidth) / 2;
    int upperLeftY = (screenHeight - windowHeight) / 2;
    frame.setLocation(upperLeftX, upperLeftY);
    frame.setVisible(true);

    Trace.exit();
}

From source file:weave.utils.BugReportUtils.java

public static void showBugReportDialog(final Throwable e) throws HeadlessException {
    Settings.canQuit = false;/*from ww  w. j av a  2  s .com*/

    final BugReportWindow brw = BugReportWindow.instance(e);
    TraceUtils.traceln(TraceUtils.STDOUT, "");
    TraceUtils.traceln(TraceUtils.STDOUT, "!! Bug detected !!");
    TraceUtils.traceln(TraceUtils.STDOUT,
            "!! Stack Trace in " + TraceUtils.getLogFile(TraceUtils.STDERR).getAbsolutePath());
    TraceUtils.traceln(TraceUtils.STDOUT, "");

    brw.addWindowListener(new WindowListener() {
        @Override
        public void windowOpened(WindowEvent arg0) {
        }

        @Override
        public void windowIconified(WindowEvent arg0) {
        }

        @Override
        public void windowDeiconified(WindowEvent arg0) {
        }

        @Override
        public void windowDeactivated(WindowEvent arg0) {
        }

        @Override
        public void windowClosing(WindowEvent arg0) {
            TraceUtils.trace(TraceUtils.STDOUT, "-> Should send bug report?........");
            if (brw.CLOSE_OPTION == BugReportWindow.YES_OPTION) {
                TraceUtils.put(TraceUtils.STDOUT, "YES");

                String c = (brw.data.comment.trim().equals(BugReportWindow.defaultComment) ? ""
                        : brw.data.comment);
                submitReport(e, c);
            } else {
                TraceUtils.put(TraceUtils.STDOUT, "NO");
            }
            Settings.canQuit = true;
        }

        @Override
        public void windowClosed(WindowEvent arg0) {
        }

        @Override
        public void windowActivated(WindowEvent arg0) {
        }
    });
    brw.setVisible(true);
}

From source file:com.kbotpro.ui.FieldWatcher.java

public FieldWatcher(Object watchedObj) {
    this.watchedObj = watchedObj;
    initComponents();/*from   w ww  .  ja va2 s .co  m*/
    updateThread = new Thread(this);
    updateThread.start();
    this.addWindowListener(new WindowListener() {
        public void windowOpened(WindowEvent e) {
            //To change body of implemented methods use File | Settings | File Templates.
        }

        public void windowClosing(WindowEvent e) {
            active = false;
        }

        public void windowClosed(WindowEvent e) {
            //To change body of implemented methods use File | Settings | File Templates.
        }

        public void windowIconified(WindowEvent e) {
            //To change body of implemented methods use File | Settings | File Templates.
        }

        public void windowDeiconified(WindowEvent e) {
            //To change body of implemented methods use File | Settings | File Templates.
        }

        public void windowActivated(WindowEvent e) {
            //To change body of implemented methods use File | Settings | File Templates.
        }

        public void windowDeactivated(WindowEvent e) {
            //To change body of implemented methods use File | Settings | File Templates.
        }
    });
}

From source file:jmap2gml.ScriptGui.java

/**
 * Formats the window, initializes the JMap2Script object, and sets up all
 * the necessary events./*from w  ww. ja  va  2s.co  m*/
 */
public ScriptGui() {
    setTitle("jmap to gml script converter");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    getContentPane().setLayout(new GridBagLayout());

    this.addWindowListener(new WindowListener() {
        @Override
        public void windowOpened(WindowEvent we) {
        }

        @Override
        public void windowClosing(WindowEvent we) {
            saveConfig();
        }

        @Override
        public void windowClosed(WindowEvent we) {
        }

        @Override
        public void windowIconified(WindowEvent we) {
        }

        @Override
        public void windowDeiconified(WindowEvent we) {
        }

        @Override
        public void windowActivated(WindowEvent we) {
        }

        @Override
        public void windowDeactivated(WindowEvent we) {
        }
    });

    GridBagConstraints c = new GridBagConstraints();

    setResizable(true);
    setIconImage((new ImageIcon("spikeup.png")).getImage());

    jta = new JTextArea(38, 30);

    loadConfig();

    JScrollPane jsp = new JScrollPane(jta);
    jsp.setRowHeaderView(new TextLineNumber(jta));
    jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    jsp.setSize(jsp.getWidth(), 608);

    // menu bar
    JMenuBar menubar = new JMenuBar();

    // file menu
    JMenu file = new JMenu("File");

    // load button
    JMenuItem load = new JMenuItem("Load jmap");
    load.addActionListener(ae -> {
        JFileChooser fileChooser = new JFileChooser(prevDirectory);
        fileChooser.setFileFilter(new FileNameExtensionFilter("jmap file", "jmap", "jmap"));

        int returnValue = fileChooser.showOpenDialog(null);

        if (returnValue == JFileChooser.APPROVE_OPTION) {
            File selectedFile = fileChooser.getSelectedFile();

            prevDirectory = selectedFile.getAbsolutePath();

            jm2s = new ScriptFromJmap(selectedFile.getPath(), false);

            jta.setText("");
            jta.append(jm2s.toString());
            jta.setCaretPosition(0);

            writeFile.setEnabled(true);

            drawPanel.setItems(jta.getText().split("\n"));
        }
    });

    // add load to file menu
    file.add(load);

    // button to save script to file
    writeFile = new JMenuItem("Write file");
    writeFile.addActionListener(ae -> {
        if (jm2s != null) {
            PrintWriter out;
            try {
                File f = new File(
                        jm2s.getFileName().substring(0, jm2s.getFileName().lastIndexOf(".jmap")) + ".gml");
                out = new PrintWriter(f);
                out.append(jm2s.toString());
                out.close();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(ScriptGui.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
    writeFile.setEnabled(false);

    JMenuItem gmx = new JMenuItem("Export as gmx");
    gmx.addActionListener(ae -> {
        String fn = String.format("%s.room.gmx", prevDirectory);

        JFileChooser fc = new JFileChooser(prevDirectory);
        fc.setSelectedFile(new File(fn));
        fc.setFileFilter(new FileNameExtensionFilter("Game Maker XML", "gmx", "gmx"));
        fc.showDialog(null, "Save");
        File f = fc.getSelectedFile();

        if (f != null) {
            try {
                GMX.itemsToGMX(drawPanel.items, new FileOutputStream(f));
            } catch (FileNotFoundException ex) {
                Logger.getLogger(ScriptGui.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });

    // add to file menu
    file.add(writeFile);
    file.add(gmx);

    // add file menu to the menubar
    menubar.add(file);

    // Edit menu

    // display menu
    JMenu display = new JMenu("Display");

    JMenuItem update = new JMenuItem("Update");

    update.addActionListener(ae -> {
        drawPanel.setItems(jta.getText().split("\n"));
    });

    display.add(update);

    JMenuItem gridToggle = new JMenuItem("Toggle Grid");
    gridToggle.addActionListener(ae -> {
        drawPanel.toggleGrid();
    });
    display.add(gridToggle);

    JMenuItem gridOptions = new JMenuItem("Modify Grid");
    gridOptions.addActionListener(ae -> {
        drawPanel.modifyGrid();
    });
    display.add(gridOptions);

    menubar.add(display);

    // sets the menubar
    setJMenuBar(menubar);

    // add the text area to the window
    c.gridx = 0;
    c.gridy = 0;
    add(jsp, c);

    // initialize the preview panel
    drawPanel = new Preview(this);
    JScrollPane scrollPane = new JScrollPane(drawPanel);

    // add preview panel to the window
    c.gridx = 1;
    c.gridwidth = 2;
    add(scrollPane, c);

    pack();
    setMinimumSize(this.getSize());
    setLocationRelativeTo(null);
    setVisible(true);
    drawPanel.setItems(jta.getText().split("\n"));
}

From source file:IHM.GialogGraph.java

public void Show() {
    VisualizationViewer<String, String> vv;
    vv = new VisualizationViewer<>(new CircleLayout<String, String>(JungGraph), dim);

    Transformer<String, String> transformer = new Transformer<String, String>() {
        @Override/*www.  j  a v  a  2s.  co m*/
        public String transform(String arg0) {
            return arg0;
        }
    };
    vv.getRenderContext().setVertexLabelTransformer(transformer);
    transformer = new Transformer<String, String>() {
        @Override
        public String transform(String arg0) {
            return arg0;
        }
    };
    vv.getRenderContext().setEdgeLabelTransformer(transformer);
    vv.getRenderer().setVertexRenderer(new MyRenderer());
    DefaultModalGraphMouse<String, Number> graphMouse = new DefaultModalGraphMouse<String, Number>();
    vv.setGraphMouse(graphMouse);
    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);

    JDialog frame = new JDialog(MymainWidow);
    frame.getContentPane().add(vv);
    frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    frame.addWindowListener(new WindowListener() {

        @Override
        public void windowOpened(WindowEvent e) {

        }

        @Override
        public void windowClosing(WindowEvent e) {
            MymainWidow.enable();
        }

        @Override
        public void windowClosed(WindowEvent e) {
            MymainWidow.enable();
        }

        @Override
        public void windowIconified(WindowEvent e) {

        }

        @Override
        public void windowDeiconified(WindowEvent e) {

        }

        @Override
        public void windowActivated(WindowEvent e) {

        }

        @Override
        public void windowDeactivated(WindowEvent e) {

        }
    });
    frame.pack();
    frame.setLocationRelativeTo(MymainWidow);
    frame.setResizable(true);
    frame.setVisible(true);
}

From source file:test.uk.co.modularaudio.util.swing.colouredtoggle.TestUseColouredTextToggle.java

public void go() throws Exception {
    final JFrame testFrame = new JFrame("TestFrame");
    testFrame.setSize(new Dimension(300, 300));
    testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final Container contentPane = testFrame.getContentPane();

    final MigLayoutStringHelper msh = new MigLayoutStringHelper();
    msh.addLayoutConstraint("fill");
    msh.addLayoutConstraint("gap 0");
    msh.addLayoutConstraint("insets 0");

    contentPane.setLayout(msh.createMigLayout());

    final Color surroundColor = Color.decode("#44BB44");
    final Color backgroundColor = Color.BLACK;

    final ToggleReceiver testReceiver = new ToggleReceiver() {

        @Override//from   w w  w .java 2s .  co  m
        public void receiveToggle(final int toggleId, final boolean active) {
            log.trace("Received a toggle of " + toggleId + " to " + active);
        }
    };

    final ColouredTextToggle ctt = new ColouredTextToggle("NoTS", "Tooltip Text", backgroundColor,
            surroundColor, false, testReceiver, 1);
    contentPane.add(ctt, "grow");

    testFrame.pack();

    testFrame.addWindowListener(new WindowListener() {

        @Override
        public void windowOpened(final WindowEvent e) {
        }

        @Override
        public void windowIconified(final WindowEvent e) {
        }

        @Override
        public void windowDeiconified(final WindowEvent e) {
        }

        @Override
        public void windowDeactivated(final WindowEvent e) {
        }

        @Override
        public void windowClosing(final WindowEvent e) {
            log.trace("Window closing. Value of control is \"" + ctt.getControlValue() + "\"");
        }

        @Override
        public void windowClosed(final WindowEvent e) {
        }

        @Override
        public void windowActivated(final WindowEvent e) {
        }
    });

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            log.trace("Showing test frame");
            testFrame.setVisible(true);
        }
    });
}