< prev index next >

test/jdk/java/awt/Focus/ModalDialogInitialFocusTest/ModalDialogInitialFocusTest.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       6382750
  27   @summary   Tests that modal dialog doesn't request extra initial focus on show.
  28   @author    anton.tarasov@sun.com: area=awt.focus
  29   @run       applet ModalDialogInitialFocusTest.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 java.lang.reflect.InvocationTargetException;
  37 
  38 public class ModalDialogInitialFocusTest extends Applet {
  39     Robot robot;
  40 
  41     Dialog dialog = new Dialog((Window)null, "Test Dialog", Dialog.ModalityType.TOOLKIT_MODAL);
  42     Button button = new Button("button");
  43 
  44     volatile static boolean passed = true;
  45 
  46     public static void main(String[] args) {
  47         ModalDialogInitialFocusTest app = new ModalDialogInitialFocusTest();
  48         app.init();
  49         app.start();
  50     }
  51 
  52     public void init() {
  53         try {
  54             robot = new Robot();
  55         } catch (AWTException e) {
  56             throw new RuntimeException("Error: unable to create robot", e);
  57         }
  58         // Create instructions for the user here, as well as set up
  59         // the environment -- set the layout manager, add buttons,
  60         // etc.
  61         this.setLayout (new BorderLayout ());
  62     }
  63 
  64     public void start() {
  65 
  66         dialog.setLayout(new FlowLayout());
  67         dialog.add(button);
  68         dialog.setBounds(800, 0, 100, 100);
  69 
  70         dialog.addFocusListener(new FocusAdapter() {
  71                 // The only expected FOCUS_GAINED is on the button.
  72                 public void focusGained(FocusEvent e) {
  73                     passed = false;
  74                 }
  75             });
  76 
  77         test();
  78     }
  79 
  80     void test() {
  81         new Thread(new Runnable() {




   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        6382750
  28   @summary   Tests that modal dialog doesn't request extra initial focus on show.
  29   @run        main ModalDialogInitialFocusTest

  30 */
  31 
  32 import java.awt.*;
  33 import java.awt.event.*;



  34 
  35 public class ModalDialogInitialFocusTest {
  36     Robot robot;
  37 
  38     Dialog dialog = new Dialog((Window)null, "Test Dialog", Dialog.ModalityType.TOOLKIT_MODAL);
  39     Button button = new Button("button");
  40 
  41     volatile static boolean passed = true;
  42 
  43     public static void main(String[] args) {
  44         ModalDialogInitialFocusTest app = new ModalDialogInitialFocusTest();
  45         app.init();
  46         app.start();
  47     }
  48 
  49     public void init() {
  50         try {
  51             robot = new Robot();
  52         } catch (AWTException e) {
  53             throw new RuntimeException("Error: unable to create robot", e);
  54         }




  55     }
  56 
  57     public void start() {
  58 
  59         dialog.setLayout(new FlowLayout());
  60         dialog.add(button);
  61         dialog.setBounds(800, 0, 100, 100);
  62 
  63         dialog.addFocusListener(new FocusAdapter() {
  64                 // The only expected FOCUS_GAINED is on the button.
  65                 public void focusGained(FocusEvent e) {
  66                     passed = false;
  67                 }
  68             });
  69 
  70         test();
  71     }
  72 
  73     void test() {
  74         new Thread(new Runnable() {


< prev index next >