35 try {
36 robot = new Robot();
37 } catch(Exception e) {
38 throw new RuntimeException("Error: unable to create robot", e);
39 }
40 }
41
42 public void start() {
43 frame.pack();
44 frame.setLocation(getLocation().x + getSize().width + 20, 0);
45 frame.setVisible(true);
46
47 waitTillShown(button);
48 frame.toFront();
49
50 robot.delay(100);
51 robot.keyPress(KeyEvent.VK_K);
52 robot.delay(100);
53 robot.keyRelease(KeyEvent.VK_K);
54
55 ((sun.awt.SunToolkit) Toolkit.getDefaultToolkit()).realSync();
56
57 if(passed) {
58 System.out.println("Test passed.");
59 } else {
60 throw new RuntimeException("Test failed.");
61 }
62 }
63
64 private void waitTillShown(Component component) {
65 while (true) {
66 try {
67 Thread.sleep(100);
68 component.getLocationOnScreen();
69 break;
70 } catch(InterruptedException ie) {
71 throw new RuntimeException(ie);
72 } catch(IllegalComponentStateException icse) {}
73 }
74 }
75 }
|
35 try {
36 robot = new Robot();
37 } catch(Exception e) {
38 throw new RuntimeException("Error: unable to create robot", e);
39 }
40 }
41
42 public void start() {
43 frame.pack();
44 frame.setLocation(getLocation().x + getSize().width + 20, 0);
45 frame.setVisible(true);
46
47 waitTillShown(button);
48 frame.toFront();
49
50 robot.delay(100);
51 robot.keyPress(KeyEvent.VK_K);
52 robot.delay(100);
53 robot.keyRelease(KeyEvent.VK_K);
54
55 robot.waitForIdle();
56
57 if(passed) {
58 System.out.println("Test passed.");
59 } else {
60 throw new RuntimeException("Test failed.");
61 }
62 }
63
64 private void waitTillShown(Component component) {
65 while (true) {
66 try {
67 Thread.sleep(100);
68 component.getLocationOnScreen();
69 break;
70 } catch(InterruptedException ie) {
71 throw new RuntimeException(ie);
72 } catch(IllegalComponentStateException icse) {}
73 }
74 }
75 }
|