4272N/A/*
4272N/A test %W% %E%
4272N/A @bug 4411534 4517274
4272N/A @summary ensures that user's requestFocus() during applet initialization
4272N/A is not ignored.
4272N/A @author prs@sparc.spb.su area=appletviewer
4272N/A @run shell AppletInitialFocusTest1.sh
4272N/A*/
1674N/A
4272N/Aimport java.applet.Applet;
4272N/Aimport java.awt.*;
4272N/Aimport java.awt.event.*;
4272N/A
1674N/Apublic class AppletInitialFocusTest1 extends Applet implements FocusListener {
4272N/A
4272N/A Button button1 = new Button("Button1");
4272N/A Button button2 = new Button("Button2");
1674N/A
4272N/A Object lock = new Object();
4272N/A
4272N/A public void init() {
4272N/A
4272N/A Component parent = this;
4272N/A while (parent != null && !(parent instanceof Window)) {
1674N/A parent = parent.getParent();
1674N/A }
1674N/A /*
1674N/A * This applet is designed to be run only with appletviewer,
1674N/A * so there always should be a toplevel frame.
1674N/A */
1674N/A if (parent == null) {
1674N/A synchronized (lock) {
1674N/A System.err.println("appletviewer not running");
1674N/A System.exit(3);
1674N/A }
1674N/A }
1674N/A button1.addFocusListener(this);
1674N/A button2.addFocusListener(this);
1674N/A add(button1);
1674N/A add(button2);
1674N/A button2.requestFocus();
1674N/A }
1674N/A
1674N/A public void focusGained(FocusEvent e) {
1674N/A if (e.getSource() == button1) {
4632N/A synchronized (lock) {
1674N/A System.err.println("failed: focus on the wrong button");
4632N/A System.exit(2);
1674N/A }
1674N/A }
1674N/A }
1674N/A
1674N/A public void focusLost(FocusEvent e) {
1674N/A }
1674N/A
1674N/A public void start() {
1674N/A Thread thread = new Thread(new Runnable() {
1674N/A public void run() {
1674N/A try {
1674N/A Thread.sleep(10000);
1674N/A synchronized (lock) {
1674N/A System.err.println("passed");
1674N/A System.exit(0);
1674N/A }
1674N/A } catch(InterruptedException e) {
1674N/A }
1674N/A }
1674N/A });
1674N/A thread.start();
1674N/A }
1674N/A}
1674N/A