test/jdk/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.java
changeset 54231 e4813eded7cb
parent 50834 9cf279436b9d
equal deleted inserted replaced
54230:d9d9655bb077 54231:e4813eded7cb
    20  * or visit www.oracle.com if you need additional information or have any
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25 test
    25   @test
    26 @bug 4799136
    26   @key headful
    27 @summary Tests that type-ahead for dialog works and doesn't block program
    27   @bug 4799136
    28 @author  area=awt.focus
    28   @summary Tests that type-ahead for dialog works and doesn't block program
    29 @run applet TestDialogTypeAhead.html
    29   @library    ../../regtesthelpers
       
    30   @modules java.desktop/sun.awt
       
    31   @build      Util
       
    32   @run main TestDialogTypeAhead
    30 */
    33 */
    31 
    34 
    32 // Note there is no @ in front of test above.  This is so that the
       
    33 //  harness will not mistake this file as a test file.  It should
       
    34 //  only see the html file as a test file. (the harness runs all
       
    35 //  valid test files, so it would run this test twice if this file
       
    36 //  were valid as well as the html file.)
       
    37 // Also, note the area= after Your Name in the author tag.  Here, you
       
    38 //  should put which functional area the test falls in.  See the
       
    39 //  AWT-core home page -> test areas and/or -> AWT team  for a list of
       
    40 //  areas.
       
    41 // Note also the 'TestDialogTypeAhead.html' in the run tag.  This should
       
    42 //  be changed to the name of the test.
       
    43 
       
    44 
       
    45 /**
       
    46  * TestDialogTypeAhead.java
       
    47  *
       
    48  * summary:
       
    49  */
       
    50 
       
    51 import java.applet.Applet;
       
    52 import java.awt.*;
    35 import java.awt.*;
    53 import java.awt.event.*;
    36 import java.awt.event.*;
    54 import java.lang.reflect.InvocationTargetException;
    37 import java.lang.reflect.InvocationTargetException;
    55 import test.java.awt.regtesthelpers.Util;
    38 
    56 
    39 public class TestDialogTypeAhead {
    57 //Automated tests should run as applet tests if possible because they
       
    58 // get their environments cleaned up, including AWT threads, any
       
    59 // test created threads, and any system resources used by the test
       
    60 // such as file descriptors.  (This is normally not a problem as
       
    61 // main tests usually run in a separate VM, however on some platforms
       
    62 // such as the Mac, separate VMs are not possible and non-applet
       
    63 // tests will cause problems).  Also, you don't have to worry about
       
    64 // synchronisation stuff in Applet tests they way you do in main
       
    65 // tests...
       
    66 
       
    67 
       
    68 public class TestDialogTypeAhead extends Applet
       
    69 {
       
    70     //Declare things used in the test, like buttons and labels here
    40     //Declare things used in the test, like buttons and labels here
    71     static Frame f;
    41     static Frame f;
    72     static Button b;
    42     static Button b;
    73     static Dialog d;
    43     static Dialog d;
    74     static Button ok;
    44     static Button ok;
    75     static Semaphore pressSema = new Semaphore();
    45     static Semaphore pressSema = new Semaphore();
    76     static Semaphore robotSema = new Semaphore();
    46     static Semaphore robotSema = new Semaphore();
    77     static volatile boolean gotFocus = false;
    47     static volatile boolean gotFocus = false;
    78     static Robot robot;
    48     static Robot robot;
       
    49 
       
    50     public static void main(final String[] args) {
       
    51         TestDialogTypeAhead app = new TestDialogTypeAhead();
       
    52         app.init();
       
    53         app.start();
       
    54     }
       
    55 
    79     public void init()
    56     public void init()
    80     {
    57     {
    81         //Create instructions for the user here, as well as set up
       
    82         // the environment -- set the layout manager, add buttons,
       
    83         // etc.
       
    84 
       
    85         Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
    58         Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
    86                 public void eventDispatched(AWTEvent e) {
    59                 public void eventDispatched(AWTEvent e) {
    87                     System.err.println(e.toString());
    60                     System.err.println(e.toString());
    88                 }
    61                 }
    89             }, AWTEvent.KEY_EVENT_MASK);
    62             }, AWTEvent.KEY_EVENT_MASK);
    90 
    63 
    91         KeyboardFocusManager.setCurrentKeyboardFocusManager(new TestKFM());
    64         KeyboardFocusManager.setCurrentKeyboardFocusManager(new TestKFM());
    92 
       
    93         this.setLayout (new BorderLayout ());
       
    94 
    65 
    95         f = new Frame("frame");
    66         f = new Frame("frame");
    96         b = new Button("press");
    67         b = new Button("press");
    97         d = new Dialog(f, "dialog", true);
    68         d = new Dialog(f, "dialog", true);
    98         ok = new Button("ok");
    69         ok = new Button("ok");
   137 
   108 
   138     }//End  init()
   109     }//End  init()
   139 
   110 
   140     public void start ()
   111     public void start ()
   141     {
   112     {
   142         //Get things going.  Request focus, set size, et cetera
       
   143         setSize (200,200);
       
   144         setVisible(true);
       
   145         validate();
       
   146         try {
   113         try {
   147             robot = new Robot();
   114             robot = new Robot();
   148         } catch (Exception e) {
   115         } catch (Exception e) {
   149             throw new RuntimeException("Can't create robot:" + e);
   116             throw new RuntimeException("Can't create robot:" + e);
   150         }
   117         }
   151 
   118         f.setLocationRelativeTo(null);
   152         f.setVisible(true);
   119         f.setVisible(true);
   153         waitTillShown(b);
   120         waitTillShown(b);
   154         System.err.println("b is shown");
   121         System.err.println("b is shown");
   155         f.toFront();
   122         f.toFront();
   156         moveMouseOver(f);
   123         moveMouseOver(f);