Example usage for java.awt Frame dispose

List of usage examples for java.awt Frame dispose

Introduction

In this page you can find the example usage for java.awt Frame dispose.

Prototype

public void dispose() 

Source Link

Document

Releases all of the native screen resources used by this Window , its subcomponents, and all of its owned children.

Usage

From source file:TexturedText.java

/** "main program" method - construct and show */
public static void main(String[] av) {
    // create a TexturedText object, tell it to show up
    final Frame f = new Frame("TexturedText");
    TexturedText comp = new TexturedText();
    f.add(comp);//from   w  ww.ja v a  2  s .c o  m
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            f.setVisible(false);
            f.dispose();
            System.exit(0);
        }
    });
    f.pack();
    f.setLocation(200, 200);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    // Create a test frame
    Frame frame = new Frame("Hello");
    frame.add(new Label("Minimize demo"));
    frame.pack();//from www. j av a 2s.c  om

    // Show the frame
    frame.setVisible(true);

    // Sleep for 5 seconds, then minimize
    Thread.sleep(5000);
    frame.setState(Frame.ICONIFIED);
    frame.setVisible(false);
    // Sleep for 5 seconds, then restore
    Thread.sleep(5000);
    frame.setState(Frame.NORMAL);
    frame.setVisible(true);

    // Sleep for 5 seconds, then kill window
    Thread.sleep(5000);
    frame.setVisible(false);
    frame.dispose();

    // Terminate test
    System.exit(0);
}

From source file:Snippet156.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("SWT Image");
    ImageData data;/*from   ww  w.  j  a v a  2  s  .  c  o m*/
    if (args.length > 0) {
        String fileName = args[0];
        data = new ImageData(fileName);
    } else {
        data = createSampleImage(display);
    }
    final Image swtImage = new Image(display, data);
    final BufferedImage awtImage = convertToAWT(data);
    final Image swtImage2 = new Image(display, convertToSWT(awtImage));
    shell.addListener(SWT.Paint, new Listener() {
        public void handleEvent(Event e) {
            int y = 10;
            if (swtImage != null) {
                e.gc.drawImage(swtImage, 10, y);
                y += swtImage.getBounds().height + 10;
            }
            if (swtImage2 != null) {
                e.gc.drawImage(swtImage2, 10, y);
            }
        }
    });
    Frame frame = new Frame() {
        public void paint(Graphics g) {
            Insets insets = getInsets();
            if (awtImage != null) {
                g.drawImage(awtImage, 10 + insets.left, 10 + insets.top, null);
            }
        }
    };
    frame.setTitle("AWT Image");
    shell.setLocation(50, 50);
    Rectangle bounds = swtImage.getBounds();
    shell.setSize(bounds.width + 50, bounds.height * 2 + 100);
    Point size = shell.getSize();
    Point location = shell.getLocation();
    Insets insets = frame.getInsets();
    frame.setLocation(location.x + size.x + 10, location.y);
    frame.setSize(size.x - (insets.left + insets.right), size.y - (insets.top + insets.bottom));
    frame.setVisible(true);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (swtImage != null)
        swtImage.dispose();
    if (swtImage2 != null)
        swtImage.dispose();
    frame.dispose();
    System.exit(0);
}

From source file:AWTBufferedImageSWTImage.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("SWT Image");
    ImageData data;/*  ww  w . j  a v  a2  s. c  o m*/
    if (args.length > 0) {
        String fileName = args[0];
        data = new ImageData(fileName);
    } else {
        data = createSampleImage(display);
    }
    final Image swtImage = new Image(display, data);
    final BufferedImage awtImage = convertToAWT(data);
    final Image swtImage2 = new Image(display, convertToSWT(awtImage));
    shell.addListener(SWT.Paint, new Listener() {
        public void handleEvent(Event e) {
            int y = 10;
            if (swtImage != null) {
                e.gc.drawImage(swtImage, 10, y);
                y += swtImage.getBounds().height + 10;
            }
            if (swtImage2 != null) {
                e.gc.drawImage(swtImage2, 10, y);
            }
        }
    });
    Frame frame = new Frame() {
        public void paint(Graphics g) {
            Insets insets = getInsets();
            if (awtImage != null) {
                g.drawImage(awtImage, 10 + insets.left, 10 + insets.top, null);
            }
        }
    };
    frame.setTitle("AWT Image");
    shell.setLocation(50, 50);
    Rectangle bounds = swtImage.getBounds();
    shell.setSize(bounds.width + 50, bounds.height * 2 + 100);
    Point size = shell.getSize();
    Point location = shell.getLocation();
    Insets insets = frame.getInsets();
    frame.setLocation(location.x + size.x + 10, location.y);
    frame.setSize(size.x - (insets.left + insets.right), size.y - (insets.top + insets.bottom));
    frame.setVisible(true);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (swtImage != null)
        swtImage.dispose();
    if (swtImage2 != null)
        swtImage.dispose();
    frame.dispose();
    display.dispose();
    /*
     * Note: If you are using JDK 1.3.x, you need to use System.exit(0) at the
     * end of your program to exit AWT. This is because in 1.3.x, AWT does not
     * exit when the frame is disposed, because the AWT thread is not a daemon.
     * This was fixed in JDK 1.4.x with the addition of the AWT Shutdown thread.
     */
}

From source file:org.eclipse.swt.snippets.Snippet156.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("SWT Image");
    ImageData data;//  w w  w  .j  a  v  a2  s .c  o m
    if (args.length > 0) {
        String fileName = args[0];
        data = new ImageData(fileName);
    } else {
        data = createSampleImage(display);
    }
    final Image swtImage = new Image(display, data);
    final BufferedImage awtImage = convertToAWT(data);
    final Image swtImage2 = new Image(display, convertToSWT(awtImage));
    shell.addListener(SWT.Paint, e -> {
        int y = 10;
        if (swtImage != null) {
            e.gc.drawImage(swtImage, 10, y);
            y += swtImage.getBounds().height + 10;
        }
        if (swtImage2 != null) {
            e.gc.drawImage(swtImage2, 10, y);
        }
    });
    Frame frame = new Frame() {
        @Override
        public void paint(Graphics g) {
            Insets insets = getInsets();
            if (awtImage != null) {
                g.drawImage(awtImage, 10 + insets.left, 10 + insets.top, null);
            }
        }
    };
    frame.setTitle("AWT Image");
    shell.setLocation(50, 50);
    Rectangle bounds = swtImage.getBounds();
    shell.setSize(bounds.width + 50, bounds.height * 2 + 100);
    Point size = shell.getSize();
    Point location = shell.getLocation();
    Insets insets = frame.getInsets();
    frame.setLocation(location.x + size.x + 10, location.y);
    frame.setSize(size.x - (insets.left + insets.right), size.y - (insets.top + insets.bottom));
    frame.setVisible(true);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (swtImage != null)
        swtImage.dispose();
    if (swtImage2 != null)
        swtImage.dispose();
    frame.dispose();
    display.dispose();
    /* Note: If you are using JDK 1.3.x, you need to use System.exit(0) at the end of your program to exit AWT.
     * This is because in 1.3.x, AWT does not exit when the frame is disposed, because the AWT thread is not a daemon.
     * This was fixed in JDK 1.4.x with the addition of the AWT Shutdown thread.
     */
}

From source file:org.keyboardplaying.xtt.ui.action.ConfirmClearPrefsAction.java

/**
 * Calls {@link Frame#dispose()} for all windows currently existing in the application.
 *//*from   w  w  w . j  a v a  2  s.  c o m*/
private void disposeAllWindows() {
    Frame[] windows = JFrame.getFrames();
    for (Frame window : windows) {
        window.dispose();
    }
}

From source file:net.fenyo.gnetwatch.GUI.AwtGUI.java

/**
 * Terminates the repaint thread and closes any frame.
 * @param none./*  w  w w .  j a  va  2  s. c  o m*/
 * @return void.
 * @throws InterruptedException exception.
 */
// main thread
public void end() throws InterruptedException {
    // terminate the repaint thread
    repaint_thread.interrupt();
    repaint_thread.join();

    synchronized (frame_list) {
        for (final Frame frame : frame_list)
            frame.dispose();
    }
}

From source file:interpolation.InterpolantFileChooser.java

protected final void close(final Frame parent) {
    if (parent != null)
        parent.dispose();

    isFinished = true;// w w w  .  j  av a  2 s  .  c  om
}

From source file:org.micromanager.saim.plot.PlotUtils.java

/**
 * Create a frame with a plot of the data given in XYSeries overwrite any
 * previously created frame with the same title
 *
        /*from   www.jav a  2s .c om*/
 * @param title shown in the top of the plot
 * @param data array with data series to be plotted
 * @param xTitle Title of the X axis
 * @param yTitle Title of the Y axis
 * @param showShapes whether or not to draw shapes at the data points
 * @param annotation to be shown in plot
 * @return Frame that displays the data
 */
public Frame plotDataN(String title, XYSeries[] data, String xTitle, String yTitle, boolean[] showShapes,
        String annotation) {

    //Close existing frames
    Frame[] gfs = ChartFrame.getFrames();
    for (Frame f : gfs) {
        if (f.getTitle().equals(title)) {
            f.dispose();
        }
    }

    // JFreeChart code
    XYSeriesCollection dataset = new XYSeriesCollection();
    // calculate min and max to scale the graph
    double minX, minY, maxX, maxY;
    minX = data[0].getMinX();
    minY = data[0].getMinY();
    maxX = data[0].getMaxX();
    maxY = data[0].getMaxY();
    for (XYSeries d : data) {
        dataset.addSeries(d);
        if (d.getMinX() < minX) {
            minX = d.getMinX();
        }
        if (d.getMaxX() > maxX) {
            maxX = d.getMaxX();
        }
        if (d.getMinY() < minY) {
            minY = d.getMinY();
        }
        if (d.getMaxY() > maxY) {
            maxY = d.getMaxY();
        }
    }

    JFreeChart chart = ChartFactory.createScatterPlot(title, // Title
            xTitle, // x-axis Label
            yTitle, // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.lightGray);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);

    for (int i = 0; i < data.length; i++) {
        renderer.setSeriesFillPaint(i, Color.white);
        renderer.setSeriesLinesVisible(i, true);
    }

    renderer.setSeriesPaint(0, Color.blue);
    Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 4.0f, 4.0f);
    renderer.setSeriesShape(0, circle, false);

    if (data.length > 1) {
        renderer.setSeriesPaint(1, Color.red);
        Shape square = new Rectangle2D.Float(-2.0f, -2.0f, 4.0f, 4.0f);
        renderer.setSeriesShape(1, square, false);
    }
    if (data.length > 2) {
        renderer.setSeriesPaint(2, Color.darkGray);
        Shape rect = new Rectangle2D.Float(-2.0f, -1.0f, 4.0f, 2.0f);
        renderer.setSeriesShape(2, rect, false);
    }
    if (data.length > 3) {
        renderer.setSeriesPaint(3, Color.magenta);
        Shape rect = new Rectangle2D.Float(-1.0f, -2.0f, 2.0f, 4.0f);
        renderer.setSeriesShape(3, rect, false);
    }

    for (int i = 0; i < data.length; i++) {
        if (showShapes.length > i && !showShapes[i]) {
            renderer.setSeriesShapesVisible(i, false);
        }
    }

    // place annotation at 80 % of max X, maxY
    XYAnnotation an = new XYTextAnnotation(annotation, maxX - 0.2 * (maxX - minX), maxY);
    plot.addAnnotation(an);

    renderer.setUseFillPaint(true);

    final MyChartFrame graphFrame = new MyChartFrame(title, chart);
    graphFrame.getChartPanel().setMouseWheelEnabled(true);
    graphFrame.pack();
    graphFrame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent arg0) {
            graphFrame.dispose();
        }
    });

    graphFrame.setVisible(true);

    return graphFrame;
}

From source file:org.keyboardplaying.xtt.ui.UIController.java

/** Builds and shows the main window. */
public void showMainWindow() {
    /* Create UI. */
    JPanel pane = new JPanel(new GridBagLayout());

    /* Arrange the components */
    GridBagConstraints c;/*  w  w  w.  j av  a 2s . co m*/

    c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 2;
    c.fill = GridBagConstraints.BOTH;
    pane.add(makeProjectActionButton("action.construct", "action-construct", ImageSize.W_16, constructAction),
            c);

    c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = 2;
    c.fill = GridBagConstraints.BOTH;
    pane.add(makeProjectActionButton("action.deconstruct", "action-deconstruct", ImageSize.W_16,
            deconstructAction), c);

    c = new GridBagConstraints();
    c.gridx = 2;
    c.gridy = 0;
    c.gridheight = 2;
    c.fill = GridBagConstraints.BOTH;
    pane.add(makeActionButton(null, "icon-settings", ImageSize.W_32, settingsAction), c);

    Window window = makeWindow("app.name", "icon-timetracker", pane);
    window.addWindowListener(new WindowAdapter() {

        /*
         * (non-Javadoc)
         *
         * @see java.awt.event.WindowAdapter#windowClosing(java.awt.event. WindowEvent)
         */
        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            Frame[] windows = JFrame.getFrames();
            for (Frame w : windows) {
                w.dispose();
            }
        }
    });
    window.setVisible(true);
}