Search in sources :

Example 66 with SunToolkit

use of sun.awt.SunToolkit in project jdk8u_jdk by JetBrains.

the class EventWhenTest method main.

public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Frame frame = new Frame();
    try {
        Button b = new Button("Button");
        frame.setBounds(300, 300, 300, 300);
        frame.add(b);
        frame.setVisible(true);
        toolkit.realSync();
        Robot robot = new Robot();
        robot.mouseMove((int) frame.getLocationOnScreen().getX() + 150, (int) frame.getLocationOnScreen().getY() + 150);
        eventsCount = 0;
        System.out.println("Clicking mouse...");
        for (int i = 0; i < 300 && !failed; i++) {
            robot.mousePress(InputEvent.BUTTON1_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
            Thread.sleep(10);
            b.setLabel("Click: " + i);
        }
        if (eventsCount == 0) {
            throw new RuntimeException("No events were received");
        }
        if (failed) {
            throw new RuntimeException("Test failed.");
        }
        System.out.println("Clicking mouse done: " + eventsCount + " events.");
        b.requestFocusInWindow();
        toolkit.realSync();
        eventsCount = 0;
        System.out.println("Typing a key...");
        for (int i = 0; i < 300 && !failed; i++) {
            robot.keyPress(KeyEvent.VK_A);
            robot.keyRelease(KeyEvent.VK_A);
            Thread.sleep(10);
            b.setLabel("Type: " + i);
        }
        System.out.println("Key typing done: " + eventsCount + " events.");
        if (eventsCount == 0) {
            throw new RuntimeException("No events were received");
        }
        if (failed) {
            throw new RuntimeException("Test failed.");
        }
        System.out.println("Success!");
    } finally {
        frame.dispose();
    }
}
Also used : SunToolkit(sun.awt.SunToolkit)

Example 67 with SunToolkit

use of sun.awt.SunToolkit in project jdk8u_jdk by JetBrains.

the class DeadKeySystemAssertionDialog method main.

public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Frame frame = new Frame();
    frame.setSize(300, 200);
    TextField textField = new TextField();
    frame.add(textField);
    frame.setVisible(true);
    toolkit.realSync();
    textField.requestFocus();
    toolkit.realSync();
    // Check that the system assertion dialog does not block Java
    Robot robot = new Robot();
    robot.setAutoDelay(50);
    robot.keyPress(KeyEvent.VK_A);
    robot.keyRelease(KeyEvent.VK_A);
    toolkit.realSync();
    frame.setVisible(false);
    frame.dispose();
}
Also used : Frame(java.awt.Frame) SunToolkit(sun.awt.SunToolkit) TextField(java.awt.TextField) Robot(java.awt.Robot)

Example 68 with SunToolkit

use of sun.awt.SunToolkit in project jdk8u_jdk by JetBrains.

the class TextEventSequenceTest method test.

private static void test(String test) {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    createAndShowGUI(test);
    toolkit.realSync();
    initCounts();
    t.setText("Hello ");
    toolkit.realSync();
    t.append("World! !");
    toolkit.realSync();
    t.insert("from Roger Pham", 13);
    toolkit.realSync();
    t.replaceRange("Java Duke", 18, 28);
    toolkit.realSync();
    checkCounts(0, 4);
    initCounts();
    t.setText("");
    toolkit.realSync();
    t.setText("");
    toolkit.realSync();
    t.setText("");
    toolkit.realSync();
    checkCounts(1, 0);
    initCounts();
    tf.setText("Hello There!");
    toolkit.realSync();
    checkCounts(0, 1);
    initCounts();
    tf.setText("");
    toolkit.realSync();
    tf.setText("");
    toolkit.realSync();
    tf.setText("");
    toolkit.realSync();
    checkCounts(1, 0);
    f.dispose();
}
Also used : SunToolkit(sun.awt.SunToolkit)

Example 69 with SunToolkit

use of sun.awt.SunToolkit in project jdk8u_jdk by JetBrains.

the class Test6827032 method main.

public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(new NimbusLookAndFeel());
    Robot robot = new Robot();
    robot.setAutoDelay(50);
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            createAndShowGUI();
        }
    });
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            Component previewPanel = Util.findSubComponent(cc, "javax.swing.colorchooser.DefaultPreviewPanel");
            point = previewPanel.getLocationOnScreen();
        }
    });
    point.translate(5, 5);
    robot.mouseMove(point.x, point.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
Also used : SunToolkit(sun.awt.SunToolkit) NimbusLookAndFeel(javax.swing.plaf.nimbus.NimbusLookAndFeel)

Example 70 with SunToolkit

use of sun.awt.SunToolkit in project jdk8u_jdk by JetBrains.

the class bug8057893 method main.

public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    robot.setAutoDelay(50);
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    EventQueue.invokeAndWait(() -> {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        JComboBox<String> comboBox = new JComboBox<>(new String[] { "one", "two" });
        comboBox.setEditable(true);
        comboBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if ("comboBoxEdited".equals(e.getActionCommand())) {
                    isComboBoxEdited = true;
                }
            }
        });
        frame.add(comboBox);
        frame.pack();
        frame.setVisible(true);
        comboBox.requestFocusInWindow();
    });
    toolkit.realSync();
    robot.keyPress(KeyEvent.VK_A);
    robot.keyRelease(KeyEvent.VK_A);
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);
    toolkit.realSync();
    if (!isComboBoxEdited) {
        throw new RuntimeException("ComboBoxEdited event is not fired!");
    }
}
Also used : JComboBox(javax.swing.JComboBox) ActionListener(java.awt.event.ActionListener) JFrame(javax.swing.JFrame) ActionEvent(java.awt.event.ActionEvent) SunToolkit(sun.awt.SunToolkit) Robot(java.awt.Robot)

Aggregations

SunToolkit (sun.awt.SunToolkit)120 Robot (java.awt.Robot)26 Point (java.awt.Point)9 Frame (java.awt.Frame)7 JFrame (javax.swing.JFrame)7 BufferedImage (java.awt.image.BufferedImage)5 Rectangle (java.awt.Rectangle)4 FlowLayout (java.awt.FlowLayout)3 TextField (java.awt.TextField)3 Toolkit (java.awt.Toolkit)3 MouseEvent (java.awt.event.MouseEvent)3 JTableHeader (javax.swing.table.JTableHeader)3 Component (java.awt.Component)2 KeyEvent (java.awt.event.KeyEvent)2 VolatileImage (java.awt.image.VolatileImage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 URL (java.net.URL)2