java/awt/KeyboardFocusmanager/ConsumeNextMnemonicKeyTypedTest/ConsumeForModalDialogTest/ConsumeForModalDialogTest.java

Print this page

        

@@ -1,6 +1,28 @@
 /*
+ * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+/*
   test
   @bug       6391688
   @summary   Tests that next mnemonic KeyTyped is consumed for a modal dialog.
   @author    anton.tarasov@sun.com: area=awt.focus
   @run       applet ConsumeForModalDialogTest.html

@@ -27,10 +49,11 @@
     }
 
     public void init() {
         try {
             robot = new Robot();
+            robot.setAutoDelay(50);
         } catch (AWTException e) {
             throw new RuntimeException("Error: unable to create robot", e);
         }
         // Create instructions for the user here, as well as set up
         // the environment -- set the layout manager, add buttons,

@@ -40,11 +63,10 @@
             {"This is automatic test. Simply wait until it is done."
             });
     }
 
     public void start() {
-        sun.awt.SunToolkit toolkit = (sun.awt.SunToolkit)Toolkit.getDefaultToolkit();
 
         text.addKeyListener(new KeyAdapter() {
                 public void keyTyped(KeyEvent e) {
                     Sysout.println(e.toString());
                     passed = false;

@@ -74,22 +96,22 @@
 
         frame.setJMenuBar(menuBar);
         frame.setSize(100, 100);
         frame.setVisible(true);
 
-        toolkit.realSync();
+        robot.waitForIdle();
 
         if (!frame.isFocusOwner()) {
             Point loc = frame.getLocationOnScreen();
             Dimension size = frame.getSize();
             robot.mouseMove(loc.x + size.width/2, loc.y + size.height/2);
             robot.delay(10);
             robot.mousePress(MouseEvent.BUTTON1_MASK);
             robot.delay(10);
             robot.mouseRelease(MouseEvent.BUTTON1_MASK);
 
-            toolkit.realSync();
+            robot.waitForIdle();
 
             int iter = 10;
             while (!frame.isFocusOwner() && iter-- > 0) {
                 robot.delay(200);
             }

@@ -103,11 +125,11 @@
         robot.keyPress(KeyEvent.VK_F);
         robot.delay(10);
         robot.keyRelease(KeyEvent.VK_F);
         robot.keyRelease(KeyEvent.VK_ALT);
 
-        toolkit.realSync();
+        robot.waitForIdle();
 
         robot.keyPress(KeyEvent.VK_S);
         robot.delay(10);
         robot.keyRelease(KeyEvent.VK_S);