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 4092033 4529626 27 @summary Tests that toFront makes window focused unless it is non-focusable 28 @author area=awt.focus 29 @run applet ToFrontFocus.html 30 */ 31 32 /** 33 * ToFrontFocus.java 34 * 35 * summary: 36 */ 37 38 import java.applet.Applet; 39 import java.awt.*; 40 import java.awt.event.*; 41 import test.java.awt.regtesthelpers.Util; 42 43 public class ToFrontFocus extends Applet 44 { 45 //Declare things used in the test, like buttons and labels here 46 47 Frame cover, focus_frame, nonfocus_frame; 48 Button focus_button, nonfocus_button; 49 volatile boolean focus_gained = false, nonfocus_gained = false; 50 public void init() 51 { 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"); 59 cover.setBounds(100, 100, 200, 200); 60 focus_frame = new Frame("Focusable frame"); 61 focus_frame.setBounds(150, 100, 250, 150); 62 nonfocus_frame = new Frame("Non-focusable frame"); 63 nonfocus_frame.setFocusableWindowState(false); 64 nonfocus_frame.setBounds(150, 150, 250, 200); 65 focus_button = new Button("Button in focusable frame"); 66 focus_button.addFocusListener(new FocusAdapter() { 67 public void focusGained(FocusEvent e) { 68 focus_gained = true; 69 } 70 }); 71 nonfocus_button = new Button("Button in non-focusable frame"); 72 nonfocus_button.addFocusListener(new FocusAdapter() { 73 public void focusGained(FocusEvent e) { 74 nonfocus_gained = true; 75 } 76 }); 77 }//End init() 78 79 public void start () 80 { 81 //Get things going. Request focus, set size, et cetera 82 setSize (200,200); 83 show(); 84 Util.waitForIdle(null); 85 86 focus_frame.setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() { 87 public Component getInitialComponent(Window w) { 88 return null; 89 } 90 }); 91 focus_frame.setVisible(true); 92 nonfocus_frame.setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() { 93 public Component getInitialComponent(Window w) { 94 return null; 95 } 96 }); 97 nonfocus_frame.setVisible(true); 98 cover.setVisible(true); 99 100 Util.waitForIdle(null); 101 102 // So events are no generated at the creation add buttons here. 103 focus_frame.add(focus_button); | 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 4092033 4529626 28 @summary Tests that toFront makes window focused unless it is non-focusable 29 @library ../../regtesthelpers 30 @build Util 31 @run main ToFrontFocus 32 */ 33 34 import java.awt.*; 35 import java.awt.event.*; 36 import test.java.awt.regtesthelpers.Util; 37 38 public class ToFrontFocus { 39 Frame cover, focus_frame, nonfocus_frame; 40 Button focus_button, nonfocus_button; 41 volatile boolean focus_gained = false, nonfocus_gained = false; 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() 50 { 51 cover = new Frame("Cover frame"); 52 cover.setBounds(100, 100, 200, 200); 53 focus_frame = new Frame("Focusable frame"); 54 focus_frame.setBounds(150, 100, 250, 150); 55 nonfocus_frame = new Frame("Non-focusable frame"); 56 nonfocus_frame.setFocusableWindowState(false); 57 nonfocus_frame.setBounds(150, 150, 250, 200); 58 focus_button = new Button("Button in focusable frame"); 59 focus_button.addFocusListener(new FocusAdapter() { 60 public void focusGained(FocusEvent e) { 61 focus_gained = true; 62 } 63 }); 64 nonfocus_button = new Button("Button in non-focusable frame"); 65 nonfocus_button.addFocusListener(new FocusAdapter() { 66 public void focusGained(FocusEvent e) { 67 nonfocus_gained = true; 68 } 69 }); 70 }//End init() 71 72 public void start () 73 { 74 Util.waitForIdle(null); 75 76 focus_frame.setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() { 77 public Component getInitialComponent(Window w) { 78 return null; 79 } 80 }); 81 focus_frame.setVisible(true); 82 nonfocus_frame.setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() { 83 public Component getInitialComponent(Window w) { 84 return null; 85 } 86 }); 87 nonfocus_frame.setVisible(true); 88 cover.setVisible(true); 89 90 Util.waitForIdle(null); 91 92 // So events are no generated at the creation add buttons here. 93 focus_frame.add(focus_button); |