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

The following examples show how to use java.awt.Frame#add() . 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: ScrollPanePreferredSize.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) {
    final Dimension expected = new Dimension(300, 300);
    final Frame frame = new Frame();
    final ScrollPane sp = new ScrollPane();
    sp.setSize(expected);
    frame.add(sp);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    sleep();
    final Dimension size = frame.getSize();
    if (size.width < expected.width || size.height < expected.height) {
        throw new RuntimeException(
                "Expected size: >= " + expected + ", actual size: " + size);
    }
    frame.dispose();
}
 
Example 2
Source File: MultiResolutionCursorTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    //Get things going.  Request focus, set size, et cetera
    setSize(200, 200);
    setVisible(true);
    validate();

    final Image image = new MultiResolutionCursor();

    int center = sizes[0] / 2;
    Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(
            image, new Point(center, center), "multi-resolution cursor");

    Frame frame = new Frame("Test Frame");
    frame.setSize(300, 300);
    frame.setLocation(300, 50);
    frame.add(new Label("Move cursor here"));
    frame.setCursor(cursor);
    frame.setVisible(true);
}
 
Example 3
Source File: R2303044ListSelection.java    From jdk8u-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 4
Source File: MultiResolutionCursorTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    //Get things going.  Request focus, set size, et cetera
    setSize(200, 200);
    setVisible(true);
    validate();

    final Image image = new MultiResolutionCursor();

    int center = sizes[0] / 2;
    Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(
            image, new Point(center, center), "multi-resolution cursor");

    Frame frame = new Frame("Test Frame");
    frame.setSize(300, 300);
    frame.setLocation(300, 50);
    frame.add(new Label("Move cursor here"));
    frame.setCursor(cursor);
    frame.setVisible(true);
}
 
Example 5
Source File: VncClient.java    From cosmic with Apache License 2.0 6 votes vote down vote up
private Frame createVncClientMainWindow(final BufferedImageCanvas canvas, final String title) {
    // Create AWT windows
    final Frame frame = new Frame(title + " - VNCle");

    // Use scrolling pane to support screens, which are larger than ours
    final ScrollPane scroller = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
    scroller.add(canvas);
    scroller.setSize(this.screen.getFramebufferWidth(), this.screen.getFramebufferHeight());

    frame.add(scroller);
    frame.pack();
    frame.setVisible(true);

    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(final WindowEvent evt) {
            frame.setVisible(false);
            shutdown();
        }
    });

    return frame;
}
 
Example 6
Source File: MultiResolutionCursorTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    //Get things going.  Request focus, set size, et cetera
    setSize(200, 200);
    setVisible(true);
    validate();

    final Image image = new MultiResolutionCursor();

    int center = sizes[0] / 2;
    Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(
            image, new Point(center, center), "multi-resolution cursor");

    Frame frame = new Frame("Test Frame");
    frame.setSize(300, 300);
    frame.setLocation(300, 50);
    frame.add(new Label("Move cursor here"));
    frame.setCursor(cursor);
    frame.setVisible(true);
}
 
Example 7
Source File: MultiResolutionSplashTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 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);
        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 8
Source File: HoveringAndDraggingTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void start() {
    String[] instructions = new String[] {
        "1. Notice components in test window: main-panel, box-for-text,"
            +" 2 scroll-sliders, and 4 scroll-buttons.",
        "2. Hover mouse over box-for-text."
            +" Make sure, that mouse cursor is TextCursor (a.k.a. \"beam\").",
        "3. Hover mouse over each of components (see item 1), except for box-for-text."
            +" Make sure, that cursor is DefaultCursor (arrow).",
        "4. Drag mouse (using any mouse button) from box-for-text to every"
            +" component in item 1, and also outside application window."
            +" Make sure, that cursor remains TextCursor while mouse button is pressed.",
        "5. Repeat item 4 for each other component in item 1, except for box-for-text,"
            +" _but_ now make sure that cursor is DefaultCursor.",
        "6. If cursor behaves as described in items 2-3-4-5, then test passed; otherwise it failed."
    };
    Sysout.createDialogWithInstructions( instructions );

    Panel panel = new Panel();
    panel.setLayout( new GridLayout(3,3) );

    for( int y=0; y<3; ++y ) {
        for( int x=0; x<3; ++x ) {
            if( x==1 && y==1 ) {
                panel.add( new TextArea( bigString() ) );
            } else {
                panel.add( new Panel() );
            }
        }
    }

    Frame frame = new Frame( "TextArea cursor icon test" );
    frame.setSize( 300, 300 );
    frame.add( panel );
    frame.setVisible( true );
}
 
Example 9
Source File: SharedMemoryPixmapsTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/** Creates a new instance of SharedMemoryPixmapsTest */
public SharedMemoryPixmapsTest() {
    testFrame = new Frame("SharedMemoryPixmapsTest");
    testFrame.add(new TestComponent());
    testFrame.setUndecorated(true);
    testFrame.setResizable(false);
    testFrame.pack();
    testFrame.setLocationRelativeTo(null);
    testFrame.setVisible(true);
    testFrame.toFront();
}
 
Example 10
Source File: SelectionInvisibleTest.java    From openjdk-jdk8u-backup 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();
        frame.setSize(300, 200);
        TextField textField = new TextField(TEXT + LAST_WORD, 30);
        Panel panel = new Panel(new FlowLayout());
        panel.add(textField);
        frame.add(panel);
        frame.setVisible(true);

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

        Robot robot = new Robot();
        robot.setAutoDelay(50);

        Point point = textField.getLocationOnScreen();
        int x = point.x + textField.getWidth() / 2;
        int y = point.y + textField.getHeight() / 2;
        robot.mouseMove(x, y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        toolkit.realSync();

        robot.mousePress(InputEvent.BUTTON1_MASK);
        int N = 10;
        int dx = textField.getWidth() / N;
        for (int i = 0; i < N; i++) {
            x += dx;
            robot.mouseMove(x, y);
        }
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        toolkit.realSync();

        if (!textField.getSelectedText().endsWith(LAST_WORD)) {
            throw new RuntimeException("Last word is not selected!");
        }
    }
 
Example 11
Source File: SharedMemoryPixmapsTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/** Creates a new instance of SharedMemoryPixmapsTest */
public SharedMemoryPixmapsTest() {
    testFrame = new Frame("SharedMemoryPixmapsTest");
    testFrame.add(new TestComponent());
    testFrame.setUndecorated(true);
    testFrame.setResizable(false);
    testFrame.pack();
    testFrame.setLocationRelativeTo(null);
    testFrame.setVisible(true);
    testFrame.toFront();
}
 
Example 12
Source File: HoveringAndDraggingTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void start() {
    String[] instructions = new String[] {
        "1. Notice components in test window: main-panel, box-for-text,"
            +" 2 scroll-sliders, and 4 scroll-buttons.",
        "2. Hover mouse over box-for-text."
            +" Make sure, that mouse cursor is TextCursor (a.k.a. \"beam\").",
        "3. Hover mouse over each of components (see item 1), except for box-for-text."
            +" Make sure, that cursor is DefaultCursor (arrow).",
        "4. Drag mouse (using any mouse button) from box-for-text to every"
            +" component in item 1, and also outside application window."
            +" Make sure, that cursor remains TextCursor while mouse button is pressed.",
        "5. Repeat item 4 for each other component in item 1, except for box-for-text,"
            +" _but_ now make sure that cursor is DefaultCursor.",
        "6. If cursor behaves as described in items 2-3-4-5, then test passed; otherwise it failed."
    };
    Sysout.createDialogWithInstructions( instructions );

    Panel panel = new Panel();
    panel.setLayout( new GridLayout(3,3) );

    for( int y=0; y<3; ++y ) {
        for( int x=0; x<3; ++x ) {
            if( x==1 && y==1 ) {
                panel.add( new TextArea( bigString() ) );
            } else {
                panel.add( new Panel() );
            }
        }
    }

    Frame frame = new Frame( "TextArea cursor icon test" );
    frame.setSize( 300, 300 );
    frame.add( panel );
    frame.setVisible( true );
}
 
Example 13
Source File: SetEnabledPerformance.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void createAndShowGUI() {
    frame = new Frame();
    frame.setLayout(new FlowLayout(FlowLayout.CENTER, 25, 0));
    frame.setSize(600, 600);
    frame.setLocationRelativeTo(null);
    for (int i = 1; i < 10001; ++i) {
        frame.add(new JButton("Button " + i));
    }
    frame.setVisible(true);
}
 
Example 14
Source File: MultiResolutionSplashTest.java    From jdk8u60 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 15
Source File: MultiResolutionSplashTest.java    From dragonwell8_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 16
Source File: HoveringAndDraggingTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void start() {
    String[] instructions = new String[] {
        "1. Notice components in test window: main-panel, box-for-text,"
            +" 2 scroll-sliders, and 4 scroll-buttons.",
        "2. Hover mouse over box-for-text."
            +" Make sure, that mouse cursor is TextCursor (a.k.a. \"beam\").",
        "3. Hover mouse over each of components (see item 1), except for box-for-text."
            +" Make sure, that cursor is DefaultCursor (arrow).",
        "4. Drag mouse (using any mouse button) from box-for-text to every"
            +" component in item 1, and also outside application window."
            +" Make sure, that cursor remains TextCursor while mouse button is pressed.",
        "5. Repeat item 4 for each other component in item 1, except for box-for-text,"
            +" _but_ now make sure that cursor is DefaultCursor.",
        "6. If cursor behaves as described in items 2-3-4-5, then test passed; otherwise it failed."
    };
    Sysout.createDialogWithInstructions( instructions );

    Panel panel = new Panel();
    panel.setLayout( new GridLayout(3,3) );

    for( int y=0; y<3; ++y ) {
        for( int x=0; x<3; ++x ) {
            if( x==1 && y==1 ) {
                panel.add( new TextArea( bigString() ) );
            } else {
                panel.add( new Panel() );
            }
        }
    }

    Frame frame = new Frame( "TextArea cursor icon test" );
    frame.setSize( 300, 300 );
    frame.add( panel );
    frame.setVisible( true );
}
 
Example 17
Source File: DrawTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    Frame f = new Frame("DrawTest");
    DrawTest drawTest = new DrawTest();
    drawTest.init();
    drawTest.start();

    f.add("Center", drawTest);
    f.setSize(300, 300);
    f.setVisible(true);
}
 
Example 18
Source File: SelectionInvisibleTest.java    From hottub 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();
        frame.setSize(300, 200);
        TextField textField = new TextField(TEXT + LAST_WORD, 30);
        Panel panel = new Panel(new FlowLayout());
        panel.add(textField);
        frame.add(panel);
        frame.setVisible(true);

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

        Robot robot = new Robot();
        robot.setAutoDelay(50);

        Point point = textField.getLocationOnScreen();
        int x = point.x + textField.getWidth() / 2;
        int y = point.y + textField.getHeight() / 2;
        robot.mouseMove(x, y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        toolkit.realSync();

        robot.mousePress(InputEvent.BUTTON1_MASK);
        int N = 10;
        int dx = textField.getWidth() / N;
        for (int i = 0; i < N; i++) {
            x += dx;
            robot.mouseMove(x, y);
        }
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        toolkit.realSync();

        if (!textField.getSelectedText().endsWith(LAST_WORD)) {
            throw new RuntimeException("Last word is not selected!");
        }
    }
 
Example 19
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 20
Source File: GetScreenLocTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws AWTException {
    robot = new Robot();
    Frame bigOne = new Frame();
    bigOne.setSize(200, 200);
    bigOne.setLocationRelativeTo(null);
    bigOne.setVisible(true);
    Frame f = new Frame();
    f.setLayout(new BorderLayout());
    f.setSize(120, 150);
    f.setLocationRelativeTo(null);
    Canvas c = new MyCanvas();
    f.add(c, BorderLayout.CENTER);
    c.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            switch(state) {
                case 0: // the first event should be (0,0)
                    if (e.getX() != 0 || e.getY() != 0) {
                        System.out.println("state 0: wrong location" + e);
                        break;
                    }
                    state++;
                    break;
                case 1: // the second event should be (1,1)
                    if (e.getX() != 1 || e.getY() != 1) {
                        System.out.println("state 1: wrong location " + e);
                        break;
                    }
                    state++;
                    break;
                case 2: // this should never happen
                    System.out.println("state 2: wrong location " + e);
            }
        }
    });
    f.pack();
    f.setVisible(true);
    bigPause();

    Point p = c.getLocationOnScreen();
    doPress(p);
    p.x += 1;
    p.y += 1;
    doPress(p);
    p.x -= 2;
    p.y -= 2;
    doPress(p);
    bigPause();

    f.dispose();
    bigOne.dispose();

    // ...and at the end the state should be 2
    if (state != 2) {
        throw new RuntimeException("wrong state: " + state);
    }
}