Example usage for javax.swing JFrame addWindowListener

List of usage examples for javax.swing JFrame addWindowListener

Introduction

In this page you can find the example usage for javax.swing JFrame addWindowListener.

Prototype

public synchronized void addWindowListener(WindowListener l) 

Source Link

Document

Adds the specified window listener to receive window events from this window.

Usage

From source file:sample.fa.ScriptRunnerApplication.java

void createGUI() {
    Box buttonBox = Box.createHorizontalBox();

    JButton loadButton = new JButton("Load");
    loadButton.addActionListener(this::loadScript);
    buttonBox.add(loadButton);/*w  ww.ja v a2 s .com*/

    JButton saveButton = new JButton("Save");
    saveButton.addActionListener(this::saveScript);
    buttonBox.add(saveButton);

    JButton executeButton = new JButton("Execute");
    executeButton.addActionListener(this::executeScript);
    buttonBox.add(executeButton);

    languagesModel = new DefaultComboBoxModel();

    ScriptEngineManager sem = new ScriptEngineManager();
    for (ScriptEngineFactory sef : sem.getEngineFactories()) {
        languagesModel.addElement(sef.getScriptEngine());
    }

    JComboBox<ScriptEngine> languagesCombo = new JComboBox<>(languagesModel);
    JLabel languageLabel = new JLabel();
    languagesCombo.setRenderer((JList<? extends ScriptEngine> list, ScriptEngine se, int index,
            boolean isSelected, boolean cellHasFocus) -> {
        ScriptEngineFactory sef = se.getFactory();
        languageLabel.setText(sef.getEngineName() + " - " + sef.getLanguageName() + " (*."
                + String.join(", *.", sef.getExtensions()) + ")");
        return languageLabel;
    });
    buttonBox.add(Box.createHorizontalGlue());
    buttonBox.add(languagesCombo);

    scriptContents = new JTextArea();
    scriptContents.setRows(8);
    scriptContents.setColumns(40);

    scriptResults = new JTextArea();
    scriptResults.setEditable(false);
    scriptResults.setRows(8);
    scriptResults.setColumns(40);

    JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scriptContents, scriptResults);

    JFrame frame = new JFrame("Script Runner");
    frame.add(buttonBox, BorderLayout.NORTH);
    frame.add(jsp, BorderLayout.CENTER);

    frame.pack();
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    frame.setVisible(true);
}

From source file:TradeMonitorGui.java

private XYPlot createChartFrame(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Average Stock Price over 1 minute", "Time",
            "Price in USD", dataset, true, true, false);
    XYPlot plot = chart.getXYPlot();//from  ww  w . j  ava 2s  .c  o  m
    plot.setBackgroundPaint(new Color(245, 245, 245));
    plot.setDomainGridlinePaint(Color.BLACK);
    plot.setRangeGridlinePaint(Color.BLACK);

    final JFrame frame = new JFrame();
    frame.setBackground(Color.WHITE);
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    frame.setTitle("Trade Monitor");
    frame.setBounds(WINDOW_X, WINDOW_Y, WINDOW_WIDTH, WINDOW_HEIGHT);
    frame.setLayout(new BorderLayout());
    frame.add(new ChartPanel(chart));
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent windowEvent) {
            avgPrices.removeEntryListener(listenerId);
        }
    });
    frame.setVisible(true);
    return plot;
}

From source file:br.univali.ps.ui.telas.TelaPrincipal.java

private void instalarObservadorJanela() {
    JFrame frame = Lancador.getJFrame();
    if (frame == null)
        return;//from w  w  w  . j a va 2s  .  c  o m

    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            fecharAplicativo();
        }

        @Override
        public void windowOpened(WindowEvent e) {
            Configuracoes configuracoes = Configuracoes.getInstancia();
            if (configuracoes.isExibirDicasInterface()) {
                SwingUtilities.invokeLater(() -> {
                    PortugolStudio.getInstancia().getTelaDicas().setVisible(true);
                });
            }

            LOGGER.log(Level.INFO, "Janela principal aberta!");
        }

    });

    Lancador.getJFrame().addComponentListener(new ComponentAdapter() {
        @Override
        public void componentShown(ComponentEvent e) {
            if (abrindo) {
                abrindo = false;

                // Por enquanto o Andr pediu para desativar esta verificao, ela s estar disponvel 
                // no final do ano
                //verificarAtualizacaoCritica();
                if (Configuracoes.getInstancia().isExibirTutorialUso()) {
                    //TODO: criar e executar tutorial de uso antes de iniciar o Portugol
                    dispararProcessosAbertura();
                } else {
                    dispararProcessosAbertura();
                }
            }
        }
    });
}

From source file:support.SystemMonitorGui.java

private XYPlot createChartFrame(XYSeries series) {
    XYSeriesCollection dataSet = new XYSeriesCollection();
    dataSet.addSeries(series);/* w w  w .j  av a2  s  .com*/
    JFreeChart chart = ChartFactory.createXYLineChart("Memory Allocation Rate", "Time (ms)",
            "Allocation Rate (MB/s)", dataSet, PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.DARK_GRAY);
    plot.setRangeGridlinePaint(Color.DARK_GRAY);
    plot.getRenderer().setSeriesPaint(0, Color.BLUE);

    JFrame frame = new JFrame();
    frame.setBackground(Color.WHITE);
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    frame.setTitle("Hazelcast Jet Source Builder Sample");
    frame.setBounds(WINDOW_X, WINDOW_Y, WINDOW_WIDTH, WINDOW_HEIGHT);
    frame.setLayout(new BorderLayout());
    frame.add(new ChartPanel(chart));
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent windowEvent) {
            hzMap.removeEntryListener(entryListenerId);
        }
    });
    frame.setVisible(true);
    return plot;
}

From source file:support.TradingVolumeGui.java

private CategoryPlot createChartFrame(CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart("Trading Volume", "Stock", "Volume, USD", dataset,
            PlotOrientation.HORIZONTAL, true, true, false);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.DARK_GRAY);
    plot.setRangeGridlinePaint(Color.DARK_GRAY);
    plot.getRenderer().setSeriesPaint(0, Color.BLUE);

    JFrame frame = new JFrame();
    frame.setBackground(Color.WHITE);
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    frame.setTitle("Hazelcast Jet Source Builder Sample");
    frame.setBounds(WINDOW_X, WINDOW_Y, WINDOW_WIDTH, WINDOW_HEIGHT);
    frame.setLayout(new BorderLayout());
    frame.add(new ChartPanel(chart));
    frame.setVisible(true);/*from w  w  w . j a  v  a2 s  .  c  om*/
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent windowEvent) {
            hzMap.removeEntryListener(entryListenerId);
        }
    });
    return plot;
}

From source file:com.diversityarrays.kdxplore.heatmap.AskForPositionNamesAndTraitInstancePanel.java

public void addHeatMapFrame(HeatMapPanelParameters hmpp, JFrame frame) {
    parametersInUse.put(frame, hmpp);//from  w  w  w  . j  av  a 2  s  . c  o  m
    frame.addWindowListener(windowCloseListener);
    table.repaint();
}

From source file:com.mirth.connect.plugins.imageviewer.ImageViewer.java

public void viewAttachments(String channelId, Long messageId, String attachmentId) {

    JFrame frame = new JFrame("Image Viewer");

    try {/*  w  w w. ja va2  s  .  com*/

        Attachment attachment = parent.mirthClient.getAttachment(channelId, messageId, attachmentId);
        byte[] rawData = attachment.getContent();
        ByteArrayInputStream bis = new ByteArrayInputStream(rawData);

        image = ImageIO.read(new Base64InputStream(bis));

        JScrollPane pictureScrollPane = new JScrollPane(new JLabel(new ImageIcon(image)));
        pictureScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        pictureScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        frame.add(pictureScrollPane);

        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                e.getWindow().dispose();
            }
        });

        frame.pack();

        int imageWidth = image.getWidth();
        int imageHeight = image.getHeight();

        // Resize the frame so that it fits and scrolls images larger than
        // 800x600 properly.
        if (imageWidth > 800 || imageHeight > 600) {
            int width = imageWidth;
            int height = imageHeight;
            if (imageWidth > 800) {
                width = 800;
            }
            if (imageHeight > 600) {
                height = 600;
            }

            // Also add the scrollbars to the window width if necessary.
            Integer scrollBarWidth = (Integer) UIManager.get("ScrollBar.width");
            int verticalScrollBar = 0;
            int horizontalScrollBar = 0;

            if (width == 800) {
                horizontalScrollBar = scrollBarWidth.intValue();
            }
            if (height == 600) {
                verticalScrollBar = scrollBarWidth.intValue();
            }

            // Also add the window borders to the width.
            width = width + frame.getInsets().left + frame.getInsets().right + verticalScrollBar;
            height = height + frame.getInsets().top + frame.getInsets().bottom + horizontalScrollBar;

            frame.setSize(width, height);
        }

        Dimension dlgSize = frame.getSize();
        Dimension frmSize = parent.getSize();
        Point loc = parent.getLocation();

        if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) {
            frame.setLocationRelativeTo(null);
        } else {
            frame.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
                    (frmSize.height - dlgSize.height) / 2 + loc.y);
        }

        frame.setVisible(true);
    } catch (Exception e) {
        parent.alertThrowable(parent, e);
    }
}

From source file:it.unibo.alchemist.boundary.monitors.Generic2DDisplay.java

private void bindKeys() {
    bindKey(KeyEvent.VK_S, () -> {
        if (status == ViewStatus.SELECTING) {
            resetStatus();// w w w  .  j ava 2s.  co m
            this.selectedNodes.clear();
        } else if (!isInteracting()) {
            this.status = ViewStatus.SELECTING;
        }
        this.repaint();
    });
    bindKey(KeyEvent.VK_O, () -> {
        if (status == ViewStatus.SELECTING) {
            this.status = ViewStatus.MOVING;
        }
    });
    bindKey(KeyEvent.VK_C, () -> {
        if (status == ViewStatus.SELECTING) {
            this.status = ViewStatus.CLONING;
        }
    });
    bindKey(KeyEvent.VK_E, () -> {
        if (status == ViewStatus.SELECTING) {
            this.status = ViewStatus.MOLECULING;
            final JFrame mol = Generic2DDisplay.makeFrame("Moleculing",
                    new MoleculeInjectorGUI<>(selectedNodes));
            mol.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            mol.addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosed(final WindowEvent e) {
                    selectedNodes.clear();
                    resetStatus();
                }
            });
        }
    });
    bindKey(KeyEvent.VK_D, () -> {
        if (status == ViewStatus.SELECTING) {
            this.status = ViewStatus.DELETING;
            for (final Node<T> n : selectedNodes) {
                currentEnv.removeNode(n);
            }
            final Simulation<T> sim = currentEnv.getSimulation();
            sim.schedule(() -> update(currentEnv, sim.getTime()));
            resetStatus();
        }
    });
    bindKey(KeyEvent.VK_M, () -> setMarkCloserNode(!isCloserNodeMarked()));
    bindKey(KeyEvent.VK_L, () -> setDrawLinks(!paintLinks));
    bindKey(KeyEvent.VK_P, () -> Optional.ofNullable(currentEnv.getSimulation()).ifPresent(sim -> {
        if (sim.getStatus() == Status.RUNNING) {
            sim.pause();
        } else {
            sim.play();
        }
    }));
    bindKey(KeyEvent.VK_R, () -> setRealTime(!isRealTime()));
    bindKey(KeyEvent.VK_LEFT, () -> setStep(Math.max(1, st - Math.max(st / 10, 1))));
    bindKey(KeyEvent.VK_RIGHT, () -> setStep(Math.max(st, st + Math.max(st / 10, 1))));
}

From source file:edu.ku.brc.specify.ui.AppBase.java

/**
 * Bring up the PPApp demo by showing the frame (only applicable if coming up
 * as an application, not an applet);//from  w  ww  . j  a  va2  s  .c  om
 */
public void showApp() {
    JFrame f = getFrame();
    f.setTitle(getTitle());
    f.getContentPane().add(this, BorderLayout.CENTER);
    f.pack();

    f.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            doExit(true);
        }
    });

    UIHelper.centerWindow(f);
    Rectangle r = f.getBounds();
    int x = AppPreferences.getLocalPrefs().getInt("APP.X", r.x);
    int y = AppPreferences.getLocalPrefs().getInt("APP.Y", r.y);
    int w = AppPreferences.getLocalPrefs().getInt("APP.W", r.width);
    int h = AppPreferences.getLocalPrefs().getInt("APP.H", r.height);
    UIHelper.positionAndFitToScreen(f, x, y, w, h);

    f.setVisible(true);
}

From source file:com.jug.MotherMachine.java

/**
 * Initializes the MotherMachine main app. This method contains platform
 * specific code like setting icons, etc.
 *
 * @param guiFrame//from www .j  av a 2 s.com
 *            the JFrame containing the MotherMachine.
 */
private void initMainWindow(final JFrame guiFrame) {
    guiFrame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(final WindowEvent we) {
            saveParams();
            System.exit(0);
        }
    });
    //      final java.net.URL url = MotherMachine.class.getResource( "gui/media/IconMotherMachine128.png" );
    //      final Toolkit kit = Toolkit.getDefaultToolkit();
    //      final Image img = kit.createImage( url );
    //      if ( !OSValidator.isMac() ) {
    //         guiFrame.setIconImage( img );
    //      }
    //      if ( OSValidator.isMac() ) {
    //         Application.getApplication().setDockIconImage( img );
    //      }
}