< prev index next >

test/jdk/java/awt/Focus/ShowFrameCheckForegroundTest/ShowFrameCheckForegroundTest.java

Print this page




  49             robot.keyPress(KeyEvent.VK_SPACE);
  50             robot.delay(50);
  51             robot.keyRelease(KeyEvent.VK_SPACE);
  52         }
  53     };
  54 
  55 
  56     public static void main(String[] args) {
  57         ShowFrameCheckForegroundTest app = new ShowFrameCheckForegroundTest();
  58         app.init();
  59         app.start();
  60     }
  61 
  62     public void init() {
  63         robot = Util.createRobot();
  64     }
  65 
  66     public void start() {
  67         showButton.addActionListener(new ActionListener() {
  68             public void actionPerformed(ActionEvent e) {
  69                 Util.showWindowWait(testToplevel);
  70             }
  71         });
  72         nofocusFrame.add(showButton);
  73         nofocusFrame.pack();
  74         nofocusFrame.setFocusableWindowState(false);
  75         nofocusFrame.setLocation(200, 200);
  76         nofocusFrame.setVisible(true);
  77         Util.waitForIdle(robot);
  78 
  79         robot.delay(3000);
  80 
  81         // 1. Show the toplvel without clicking into the non-focusable frame.
  82         test(frame, 1);
  83         test(dialog1, 1);
  84         test(dialog2, 1);
  85 
  86         // 2. Showing the toplvel via clicking into the non-focusable frame.
  87         test(frame, 2);
  88         test(dialog1, 2);
  89         test(dialog2, 2);
  90 
  91         System.out.println("Test passed.");
  92     }
  93 
  94     private void test(Window toplevel, int stage) {
  95         toplevel.add(testButton);
  96         toplevel.pack();
  97         toplevel.setLocation(400, 200);
  98 
  99         switch (stage) {
 100             case 1:
 101                 Util.showWindowWait(toplevel);
 102                 break;
 103             case 2:
 104                 testToplevel = toplevel;
 105                 Util.showWindowWait(nofocusFrame);
 106                 Util.waitForIdle(robot);
 107                 Util.clickOnComp(showButton, robot);
 108                 break;
 109         }
 110         Util.waitForIdle(robot);
 111 
 112         if (!Util.trackActionPerformed(testButton, action, 2000, false)) {
 113             throw new TestFailedException("Stage " + stage + ". The toplevel " + toplevel + " wasn't made foreground on showing");
 114         }
 115         System.out.println("Stage " + stage + ". Toplevel " + toplevel + " - passed");
 116         toplevel.dispose();
 117     }
 118 }
 119 
 120 class TestFailedException extends RuntimeException {
 121     TestFailedException(String msg) {
 122         super("Test failed: " + msg);
 123     }
 124 }


  49             robot.keyPress(KeyEvent.VK_SPACE);
  50             robot.delay(50);
  51             robot.keyRelease(KeyEvent.VK_SPACE);
  52         }
  53     };
  54 
  55 
  56     public static void main(String[] args) {
  57         ShowFrameCheckForegroundTest app = new ShowFrameCheckForegroundTest();
  58         app.init();
  59         app.start();
  60     }
  61 
  62     public void init() {
  63         robot = Util.createRobot();
  64     }
  65 
  66     public void start() {
  67         showButton.addActionListener(new ActionListener() {
  68             public void actionPerformed(ActionEvent e) {
  69                 testToplevel.setVisible(true);
  70             }
  71         });
  72         nofocusFrame.add(showButton);
  73         nofocusFrame.pack();
  74         nofocusFrame.setFocusableWindowState(false);
  75         nofocusFrame.setLocation(200, 200);
  76         nofocusFrame.setVisible(true);
  77         Util.waitForIdle(robot);
  78 
  79         robot.delay(3000);
  80 
  81         // 1. Show the toplvel without clicking into the non-focusable frame.
  82         test(frame, 1);
  83         test(dialog1, 1);
  84         test(dialog2, 1);
  85 
  86         // 2. Showing the toplvel via clicking into the non-focusable frame.
  87         test(frame, 2);
  88         test(dialog1, 2);
  89         test(dialog2, 2);
  90 
  91         System.out.println("Test passed.");
  92     }
  93 
  94     private void test(Window toplevel, int stage) {
  95         toplevel.add(testButton);
  96         toplevel.pack();
  97         toplevel.setLocation(400, 200);
  98 
  99         switch (stage) {
 100             case 1:
 101                 toplevel.setVisible(true);
 102                 break;
 103             case 2:
 104                 testToplevel = toplevel;


 105                 Util.clickOnComp(showButton, robot);
 106                 break;
 107         }
 108         Util.waitForIdle(robot);
 109 
 110         if (!Util.trackActionPerformed(testButton, action, 2000, false)) {
 111             throw new TestFailedException("Stage " + stage + ". The toplevel " + toplevel + " wasn't made foreground on showing");
 112         }
 113         System.out.println("Stage " + stage + ". Toplevel " + toplevel + " - passed");
 114         toplevel.dispose();
 115     }
 116 }
 117 
 118 class TestFailedException extends RuntimeException {
 119     TestFailedException(String msg) {
 120         super("Test failed: " + msg);
 121     }
 122 }
< prev index next >