< prev index next >

test/jdk/java/awt/Focus/AppletInitialFocusTest/AppletInitialFocusTest1.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2018, 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.

@@ -19,22 +19,40 @@
  * 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.
  */
 
-import java.applet.Applet;
 import java.awt.*;
 import java.awt.event.*;
 
-public class AppletInitialFocusTest1 extends Applet implements FocusListener {
+/*
+  @test
+  @key headful
+  @bug 4411534 4517274
+  @summary ensures that user's requestFocus() during applet initialization
+           is not ignored
+  @library ../../regtesthelpers
+  @build   Util
+  @run main AppletInitialFocusTest1
+ */
+public class AppletInitialFocusTest1 extends Frame implements FocusListener {
 
     Button button1 = new Button("Button1");
     Button button2 = new Button("Button2");
 
     Object lock = new Object();
 
+    public static void main(final String[] args) throws Exception {
+        AppletInitialFocusTest1 app = new AppletInitialFocusTest1();
+        app.init();
+        Thread.sleep(10000);
+    }
+
     public void init() {
+        setSize(200, 200);
+        setLocationRelativeTo(null);
+        setLayout(new FlowLayout());
 
         Component parent = this;
         while (parent != null && !(parent instanceof Window)) {
             parent = parent.getParent();
         }

@@ -50,36 +68,20 @@
         }
         button1.addFocusListener(this);
         button2.addFocusListener(this);
         add(button1);
         add(button2);
+        setVisible(true);
         button2.requestFocus();
     }
 
     public void focusGained(FocusEvent e) {
         if (e.getSource() == button1) {
             synchronized (lock) {
-                System.err.println("failed: focus on the wrong button");
-                System.exit(2);
+                throw new RuntimeException("failed: focus on the wrong button");
             }
         }
     }
 
     public void focusLost(FocusEvent e) {
     }
-
-    public void start() {
-        Thread thread = new Thread(new Runnable() {
-            public void run() {
-                try {
-                    Thread.sleep(10000);
-                    synchronized (lock) {
-                        System.err.println("passed");
-                        System.exit(0);
-                    }
-                } catch(InterruptedException e) {
-                }
-            }
-        });
-        thread.start();
-    }
 }
< prev index next >