test/jdk/java/awt/Focus/ToFrontFocusTest/ToFrontFocus.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   @key headful
    26   @bug 4092033 4529626
    27   @bug 4092033 4529626
    27   @summary Tests that toFront makes window focused unless it is non-focusable
    28   @summary Tests that toFront makes window focused unless it is non-focusable
    28   @author  area=awt.focus
    29   @library ../../regtesthelpers
    29   @run applet ToFrontFocus.html
    30   @build Util
       
    31   @run main ToFrontFocus
    30 */
    32 */
    31 
    33 
    32 /**
       
    33  * ToFrontFocus.java
       
    34  *
       
    35  * summary:
       
    36  */
       
    37 
       
    38 import java.applet.Applet;
       
    39 import java.awt.*;
    34 import java.awt.*;
    40 import java.awt.event.*;
    35 import java.awt.event.*;
    41 import test.java.awt.regtesthelpers.Util;
    36 import test.java.awt.regtesthelpers.Util;
    42 
    37 
    43 public class ToFrontFocus extends Applet
    38 public class ToFrontFocus {
    44  {
       
    45    //Declare things used in the test, like buttons and labels here
       
    46 
       
    47      Frame cover, focus_frame, nonfocus_frame;
    39      Frame cover, focus_frame, nonfocus_frame;
    48      Button focus_button, nonfocus_button;
    40      Button focus_button, nonfocus_button;
    49      volatile boolean focus_gained = false, nonfocus_gained = false;
    41      volatile boolean focus_gained = false, nonfocus_gained = false;
    50    public void init()
    42 
       
    43     public static void main(final String[] args) {
       
    44         ToFrontFocus app = new ToFrontFocus();
       
    45         app.init();
       
    46         app.start();
       
    47     }
       
    48 
       
    49     public void init()
    51     {
    50     {
    52       //Create instructions for the user here, as well as set up
       
    53       // the environment -- set the layout manager, add buttons,
       
    54       // etc.
       
    55 
       
    56       this.setLayout (new BorderLayout ());
       
    57 
       
    58       cover = new Frame("Cover frame");
    51       cover = new Frame("Cover frame");
    59       cover.setBounds(100, 100, 200, 200);
    52       cover.setBounds(100, 100, 200, 200);
    60       focus_frame = new Frame("Focusable frame");
    53       focus_frame = new Frame("Focusable frame");
    61       focus_frame.setBounds(150, 100, 250, 150);
    54       focus_frame.setBounds(150, 100, 250, 150);
    62       nonfocus_frame = new Frame("Non-focusable frame");
    55       nonfocus_frame = new Frame("Non-focusable frame");
    76           });
    69           });
    77     }//End  init()
    70     }//End  init()
    78 
    71 
    79    public void start ()
    72    public void start ()
    80     {
    73     {
    81       //Get things going.  Request focus, set size, et cetera
       
    82       setSize (200,200);
       
    83       show();
       
    84       Util.waitForIdle(null);
    74       Util.waitForIdle(null);
    85 
    75 
    86       focus_frame.setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
    76       focus_frame.setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
    87               public Component getInitialComponent(Window w) {
    77               public Component getInitialComponent(Window w) {
    88                   return null;
    78                   return null;