Java Code Examples for java.awt.Frame#dispose()

The following examples show how to use java.awt.Frame#dispose() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListRepaint.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) {
    for (int i = 0; i < 10; ++i) {
        final Frame frame = new Frame();
        frame.setSize(300, 300);
        frame.setLocationRelativeTo(null);
        ListRepaint list = new ListRepaint();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        list.select(0);
        frame.add(list);
        frame.setVisible(true);
        sleep();
        list.test();
        frame.dispose();
    }
}
 
Example 2
Source File: ListRepaint.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) {
    for (int i = 0; i < 10; ++i) {
        final Frame frame = new Frame();
        frame.setSize(300, 300);
        frame.setLocationRelativeTo(null);
        ListRepaint list = new ListRepaint();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        list.select(0);
        frame.add(list);
        frame.setVisible(true);
        sleep();
        list.test();
        frame.dispose();
    }
}
 
Example 3
Source File: R2303044ListSelection.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) throws HeadlessException {
    final Frame frame = new Frame("Test Frame");
    final List list = new List();
    frame.setSize(300, 200);
    list.add(ITEM_NAME);
    list.select(0);
    frame.add(list);
    frame.validate();
    frame.setVisible(true);
    sleep();
    if (!ITEM_NAME.equals(list.getSelectedItem())) {
        throw new RuntimeException("List item not selected item.");
    }
    list.removeAll();
    frame.dispose();
}
 
Example 4
Source File: ListRepaint.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) {
    for (int i = 0; i < 10; ++i) {
        final Frame frame = new Frame();
        frame.setSize(300, 300);
        frame.setLocationRelativeTo(null);
        ListRepaint list = new ListRepaint();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        list.select(0);
        frame.add(list);
        frame.setVisible(true);
        sleep();
        list.test();
        frame.dispose();
    }
}
 
Example 5
Source File: R2303044ListSelection.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) throws HeadlessException {
    final Frame frame = new Frame("Test Frame");
    final List list = new List();
    frame.setSize(300, 200);
    list.add(ITEM_NAME);
    list.select(0);
    frame.add(list);
    frame.validate();
    frame.setVisible(true);
    sleep();
    if (!ITEM_NAME.equals(list.getSelectedItem())) {
        throw new RuntimeException("List item not selected item.");
    }
    list.removeAll();
    frame.dispose();
}
 
Example 6
Source File: KeyCharTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();

        Frame frame = new Frame();
        frame.setSize(300, 300);
        frame.setVisible(true);
        toolkit.realSync();

        Robot robot = new Robot();

        robot.keyPress(KeyEvent.VK_DELETE);
        robot.keyRelease(KeyEvent.VK_DELETE);
        toolkit.realSync();

        frame.dispose();

        if (eventsCount != 3) {
            throw new RuntimeException("Wrong number of key events: " + eventsCount);
        }
    }
 
Example 7
Source File: KeyCharTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();

        Frame frame = new Frame();
        frame.setSize(300, 300);
        frame.setVisible(true);
        toolkit.realSync();

        Robot robot = new Robot();

        robot.keyPress(KeyEvent.VK_DELETE);
        robot.keyRelease(KeyEvent.VK_DELETE);
        toolkit.realSync();

        frame.dispose();

        if (eventsCount != 3) {
            throw new RuntimeException("Wrong number of key events: " + eventsCount);
        }
    }
 
Example 8
Source File: MultiResolutionSplashTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
static void testFocus() throws Exception {

        System.out.println("Focus Test!");
        Robot robot = new Robot();
        robot.setAutoDelay(50);

        Frame frame = new Frame();
        frame.setSize(100, 100);
        String test = "123";
        TextField textField = new TextField(test);
        textField.selectAll();
        frame.add(textField);
        frame.setVisible(true);
        robot.waitForIdle();

        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.keyPress(KeyEvent.VK_B);
        robot.keyRelease(KeyEvent.VK_B);
        robot.waitForIdle();

        frame.dispose();

        if(!textField.getText().equals("ab")){
            throw new RuntimeException("Focus is lost!");
        }
    }
 
Example 9
Source File: ServiceDialog.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
* Creates a  pop-up dialog for "no print service"
*/
 public static void showNoPrintService(GraphicsConfiguration gc)
 {
     Frame dlgFrame = new Frame(gc);
     JOptionPane.showMessageDialog(dlgFrame,
                                   getMsg("dialog.noprintermsg"));
     dlgFrame.dispose();
 }
 
Example 10
Source File: MultiResolutionSplashTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void testFocus() throws Exception {

        System.out.println("Focus Test!");
        Robot robot = new Robot();
        robot.setAutoDelay(50);

        Frame frame = new Frame();
        frame.setSize(100, 100);
        String test = "123";
        TextField textField = new TextField(test);
        textField.selectAll();
        frame.add(textField);
        frame.setVisible(true);
        robot.waitForIdle();

        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.keyPress(KeyEvent.VK_B);
        robot.keyRelease(KeyEvent.VK_B);
        robot.waitForIdle();

        frame.dispose();

        if(!textField.getText().equals("ab")){
            throw new RuntimeException("Focus is lost!");
        }
    }
 
Example 11
Source File: DrawXORModeTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    final DrawXORModeTest c = new DrawXORModeTest();

    final Frame f = new Frame("XOR mode test");
    f.add(c);
    f.pack();

    f.setVisible(true);

    try {
        c.checkResult();
    } finally {
        f.dispose();
    }
}
 
Example 12
Source File: NpeOnCloseTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args)
{
    Frame frame1 = new Frame("frame 1");
    frame1.setBounds(0, 0, 100, 100);
    frame1.setVisible(true);
    Util.waitForIdle(null);

    Frame frame2 = new Frame("frame 2");
    frame2.setBounds(150, 0, 100, 100);
    frame2.setVisible(true);
    Util.waitForIdle(null);

    Frame frame3 = new Frame("frame 3");
    final Dialog dialog = new Dialog(frame3, "dialog", true);
    dialog.setBounds(300, 0, 100, 100);
    EventQueue.invokeLater(new Runnable() {
            public void run() {
                dialog.setVisible(true);
            }
        });
    try {
        EventQueue.invokeAndWait(new Runnable() { public void run() {} });
        Util.waitForIdle(null);
        EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    dialog.dispose();
                }
            });
    }
    catch (InterruptedException ie) {
        throw new RuntimeException(ie);
    }
    catch (InvocationTargetException ite) {
        throw new RuntimeException(ite);
    }

    frame1.dispose();
    frame2.dispose();
    frame3.dispose();
}
 
Example 13
Source File: FrameSetSizeStressTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) {
    final Frame frame = new Frame();
    frame.setSize(200, 200);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    for (int i = 0; i < 1000; ++i) {
        frame.setSize(100, 100);
        frame.setSize(200, 200);
        frame.setSize(300, 300);
    }
    frame.dispose();
}
 
Example 14
Source File: MaximizedToMaximized.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Frame frame = new Frame();
        Robot robot = new Robot();
        final Toolkit toolkit = Toolkit.getDefaultToolkit();
        final GraphicsEnvironment graphicsEnvironment =
                GraphicsEnvironment.getLocalGraphicsEnvironment();
        final GraphicsDevice graphicsDevice =
                graphicsEnvironment.getDefaultScreenDevice();

        final Dimension screenSize = toolkit.getScreenSize();
        final Insets screenInsets = toolkit.getScreenInsets(
                graphicsDevice.getDefaultConfiguration());

        final Rectangle availableScreenBounds = new Rectangle(screenSize);

        availableScreenBounds.x += screenInsets.left;
        availableScreenBounds.y += screenInsets.top;
        availableScreenBounds.width -= (screenInsets.left + screenInsets.right);
        availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);

        frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,
                availableScreenBounds.width, availableScreenBounds.height);
        frame.setVisible(true);
        robot.waitForIdle();

        Rectangle frameBounds = frame.getBounds();
        frame.setExtendedState(Frame.MAXIMIZED_BOTH);
        robot.waitForIdle();

        Rectangle maximizedFrameBounds = frame.getBounds();

        frame.dispose();
        if (maximizedFrameBounds.width < frameBounds.width
                || maximizedFrameBounds.height < frameBounds.height) {
            throw new RuntimeException("Maximized frame is smaller than non maximized");
        }
    }
 
Example 15
Source File: RequestFocusAndHideTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException, java.lang.reflect.InvocationTargetException
{
    final Frame frame = new Frame("the test");
    frame.setLayout(new FlowLayout());
    final Button btn1 = new Button("button 1");
    frame.add(btn1);
    frame.add(new Button("button 2"));
    frame.add(new Button("button 3"));
    frame.pack();
    frame.setVisible(true);

    Robot r = Util.createRobot();
    Util.waitForIdle(r);
    Util.clickOnComp(btn1, r);
    Util.waitForIdle(r);
    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    if (kfm.getFocusOwner() != btn1) {
        throw new RuntimeException("test error: can not set focus on " + btn1 + ".");
    }

    EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                final int n_comps = frame.getComponentCount();
                for (int i = 0; i < n_comps; ++i) {
                    frame.getComponent(i).setVisible(false);
                }
            }
        });
    Util.waitForIdle(r);
    final Component focus_owner = kfm.getFocusOwner();

    if (focus_owner != null && !focus_owner.isVisible()) {
        throw new RuntimeException("we have invisible focus owner");
    }
    System.out.println("test passed");
    frame.dispose();
}
 
Example 16
Source File: FrameSetSizeStressTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) {
    final Frame frame = new Frame();
    frame.setSize(200, 200);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    for (int i = 0; i < 1000; ++i) {
        frame.setSize(100, 100);
        frame.setSize(200, 200);
        frame.setSize(300, 300);
    }
    frame.dispose();
}
 
Example 17
Source File: IncorrectDisplayModeExitFullscreen.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] args) {

        final GraphicsDevice[] devices =
                GraphicsEnvironment.getLocalGraphicsEnvironment()
                                   .getScreenDevices();
        if (devices.length < 2 || devices[0].getDisplayModes().length < 2
                || !devices[0].isFullScreenSupported()
                || !devices[1].isFullScreenSupported()) {
            System.err.println("Testcase is not applicable");
            return;
        }
        final DisplayMode defaultDM = devices[0].getDisplayMode();
        final DisplayMode[] dms = devices[0].getDisplayModes();
        DisplayMode nonDefaultDM = null;

        for (final DisplayMode dm : dms) {
            if (!dm.equals(defaultDM)) {
                nonDefaultDM = dm;
                break;
            }
        }
        if (nonDefaultDM == null) {
            System.err.println("Testcase is not applicable");
            return;
        }

        final Frame frame = new Frame();
        frame.setBackground(Color.GREEN);
        frame.setUndecorated(true);
        try {
            devices[0].setFullScreenWindow(frame);
            sleep();
            devices[0].setDisplayMode(nonDefaultDM);
            sleep();
            devices[1].setFullScreenWindow(frame);
            sleep();
            if (!defaultDM.equals(devices[0].getDisplayMode())) {
                throw new RuntimeException("DisplayMode is not restored");
            }
        } finally {
            // cleaning up
            devices[0].setFullScreenWindow(null);
            devices[1].setFullScreenWindow(null);
            frame.dispose();
        }
    }
 
Example 18
Source File: ScreenInsetsTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
{
    boolean passed = true;

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    for (GraphicsDevice gd : gds) {

        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        Rectangle gcBounds = gc.getBounds();
        Insets gcInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
        int left = gcInsets.left;
        int right = gcInsets.right;
        int bottom = gcInsets.bottom;
        int top = gcInsets.top;
        if (left < 0 || right < 0 || bottom < 0 || top < 0) {
            throw new RuntimeException("Negative value: " + gcInsets);
        }
        int maxW = gcBounds.width / 3;
        int maxH = gcBounds.height / 3;
        if (left > maxW || right > maxW || bottom > maxH || top > maxH) {
            throw new RuntimeException("Big value: " + gcInsets);
        }

        if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH))
        {
            // this state is used in the test - sorry
            continue;
        }

        Frame f = new Frame("Test", gc);
        f.setUndecorated(true);
        f.setBounds(gcBounds.x + 100, gcBounds.y + 100, 320, 240);
        f.setVisible(true);
        Util.waitForIdle(null);

        f.setExtendedState(Frame.MAXIMIZED_BOTH);
        Util.waitForIdle(null);

        Rectangle fBounds = f.getBounds();
        // workaround: on Windows maximized windows have negative coordinates
        if (fBounds.x < gcBounds.x)
        {
            fBounds.width -= (gcBounds.x - fBounds.x) * 2; // width is decreased
            fBounds.x = gcBounds.x;
        }
        if (fBounds.y < gcBounds.y)
        {
            fBounds.height -= (gcBounds.y - fBounds.y) * 2; // height is decreased
            fBounds.y = gcBounds.y;
        }
        Insets expected = new Insets(fBounds.y - gcBounds.y,
                                     fBounds.x - gcBounds.x,
                                     gcBounds.y + gcBounds.height - fBounds.y - fBounds.height,
                                     gcBounds.x + gcBounds.width - fBounds.x - fBounds.width);

        if (!expected.equals(gcInsets))
        {
            passed = false;
            System.err.println("Wrong insets for GraphicsConfig: " + gc);
            System.err.println("\tExpected: " + expected);
            System.err.println("\tActual: " + gcInsets);
        }

        f.dispose();
    }

    if (!passed)
    {
        throw new RuntimeException("TEST FAILED: Toolkit.getScreenInsets() returns wrong value for some screens");
    }
}
 
Example 19
Source File: GUIHelper.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
/**
	 * A copy of Curtis's method
	 * 
	 * https://github.com/openmicroscopy/bioformats/blob/v4.4.8/components/loci-plugins/src/loci/plugins/util/WindowTools.java#L72
	 * 
	 *
	 * @param pane
	 */
	public static void addScrollBars(Container pane) {
//        * <dependency>
//        * <groupId>${bio-formats.groupId}</groupId>
//        * <artifactId>loci_plugins</artifactId>
//        * <version>${bio-formats.version}</version>
//        * </dependency>

		GridBagLayout layout = (GridBagLayout) pane.getLayout();

		// extract components
		int count = pane.getComponentCount();
		Component[] c = new Component[count];
		GridBagConstraints[] gbc = new GridBagConstraints[count];
		for (int i = 0; i < count; i++) {
			c[i] = pane.getComponent(i);
			gbc[i] = layout.getConstraints(c[i]);
		}

		// clear components
		pane.removeAll();
		layout.invalidateLayout(pane);

		// create new container panel
		Panel newPane = new Panel();
		GridBagLayout newLayout = new GridBagLayout();
		newPane.setLayout(newLayout);
		for (int i = 0; i < count; i++) {
			newLayout.setConstraints(c[i], gbc[i]);
			newPane.add(c[i]);
		}

		// HACK - get preferred size for container panel
		// NB: don't know a better way:
		// - newPane.getPreferredSize() doesn't work
		// - newLayout.preferredLayoutSize(newPane) doesn't work
		Frame f = new Frame();
		f.setLayout(new BorderLayout());
		f.add(newPane, BorderLayout.CENTER);
		f.pack();
		final Dimension size = newPane.getSize();
		f.remove(newPane);
		f.dispose();

		// compute best size for scrollable viewport
		size.width += 25;
		size.height += 15;
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		int maxWidth = 7 * screen.width / 8;
		int maxHeight = 3 * screen.height / 4;
		if (size.width > maxWidth)
			size.width = maxWidth;
		if (size.height > maxHeight)
			size.height = maxHeight;

		// create scroll pane
		ScrollPane scroll = new ScrollPane() {
			private static final long serialVersionUID = 1L;

			public Dimension getPreferredSize() {
				return size;
			}
		};
		scroll.add(newPane);

		// add scroll pane to original container
		GridBagConstraints constraints = new GridBagConstraints();
		constraints.gridwidth = GridBagConstraints.REMAINDER;
		constraints.fill = GridBagConstraints.BOTH;
		constraints.weightx = 1.0;
		constraints.weighty = 1.0;
		layout.setConstraints(scroll, constraints);
		pane.add(scroll);
	}
 
Example 20
Source File: DrawImageBilinear.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    boolean show = false;
    for (String arg : args) {
        if ("-show".equals(arg)) {
            show = true;
        }
    }

    String arch = System.getProperty("os.arch");
    boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl");
    skipOglTextureTest = isOglEnabled && ("sparc".equals(arch));
    System.out.println("Skip OpenGL texture test: " + skipOglTextureTest);

    DrawImageBilinear test = new DrawImageBilinear();
    Frame frame = new Frame();
    frame.add(test);
    frame.pack();
    frame.setVisible(true);

    // Wait until the component's been painted
    synchronized (test) {
        while (!done) {
            try {
                test.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed: Interrupted");
            }
        }
    }

    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    if (gc.getColorModel() instanceof IndexColorModel) {
        System.out.println("IndexColorModel detected: " +
                           "test considered PASSED");
        frame.dispose();
        return;
    }

    if (!show) {
        frame.dispose();
    }
    if (capture == null) {
        throw new RuntimeException("Failed: capture is null");
    }

    // Test background color
    int pixel = capture.getRGB(5, 5);
    if (pixel != 0xffffffff) {
        throw new RuntimeException("Failed: Incorrect color for " +
                                   "background");
    }

    // Test pixels
    testRegion(capture, new Rectangle(10, 10, 40, 40));
    testRegion(capture, new Rectangle(80, 10, 40, 40));
    testRegion(capture, new Rectangle(150, 10, 40, 40));
}