< prev index next >

test/jdk/java/awt/Focus/WindowInitialFocusTest/WindowInitialFocusTest.java

Print this page




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25   test

  26   @bug       6426132
  27   @summary   A Window should be initially focused on its showing (XAWT bug).
  28   @author    anton.tarasov@...: area=awt.focus
  29   @run       applet WindowInitialFocusTest.html

  30 */
  31 
  32 import java.awt.*;
  33 import java.awt.event.*;
  34 import java.applet.Applet;
  35 import java.util.concurrent.atomic.AtomicBoolean;
  36 import test.java.awt.regtesthelpers.Util;
  37 
  38 public class WindowInitialFocusTest extends Applet {
  39     Frame frame = new Frame("Test Frame");
  40     Window window = new Window(frame);
  41     Button button = new Button("button");
  42     AtomicBoolean focused = new AtomicBoolean(false);
  43     Robot robot;
  44 
  45     public static void main(String[] args) {
  46         WindowInitialFocusTest app = new WindowInitialFocusTest();
  47         app.init();
  48         app.start();
  49     }
  50 
  51     public void init() {
  52         // Create instructions for the user here, as well as set up
  53         // the environment -- set the layout manager, add buttons,
  54         // etc.
  55         this.setLayout (new BorderLayout ());
  56     }
  57 
  58     public void start() {
  59         frame.setBounds(800, 0, 200, 100);
  60         window.setBounds(800, 200, 200, 100);
  61         window.setLayout(new FlowLayout());
  62         window.add(button);
  63 
  64         window.addWindowFocusListener(new WindowAdapter() {
  65                 public void windowGainedFocus(WindowEvent e) {
  66                     System.out.println(e.toString());
  67                     synchronized (focused) {
  68                         focused.set(true);
  69                         focused.notifyAll();
  70                     }
  71                 }});
  72 
  73         frame.setVisible(true);
  74         try {
  75             robot = new Robot();
  76         }catch(Exception ex) {
  77             ex.printStackTrace();




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25   @test
  26   @key headful
  27   @bug        6426132
  28   @summary    A Window should be focused upon start (XAWT bug).
  29   @library    ../../regtesthelpers
  30   @build      Util
  31   @run        main WindowInitialFocusTest
  32 */
  33 
  34 import java.awt.*;
  35 import java.awt.event.*;

  36 import java.util.concurrent.atomic.AtomicBoolean;
  37 import test.java.awt.regtesthelpers.Util;
  38 
  39 public class WindowInitialFocusTest {
  40     Frame frame = new Frame("Test Frame");
  41     Window window = new Window(frame);
  42     Button button = new Button("button");
  43     AtomicBoolean focused = new AtomicBoolean(false);
  44     Robot robot;
  45 
  46     public static void main(String[] args) {
  47         WindowInitialFocusTest app = new WindowInitialFocusTest();

  48         app.start();
  49     }
  50 







  51     public void start() {
  52         frame.setBounds(800, 0, 200, 100);
  53         window.setBounds(800, 200, 200, 100);
  54         window.setLayout(new FlowLayout());
  55         window.add(button);
  56 
  57         window.addWindowFocusListener(new WindowAdapter() {
  58                 public void windowGainedFocus(WindowEvent e) {
  59                     System.out.println(e.toString());
  60                     synchronized (focused) {
  61                         focused.set(true);
  62                         focused.notifyAll();
  63                     }
  64                 }});
  65 
  66         frame.setVisible(true);
  67         try {
  68             robot = new Robot();
  69         }catch(Exception ex) {
  70             ex.printStackTrace();


< prev index next >