< prev index next >

test/jdk/java/awt/Focus/ResetMostRecentFocusOwnerTest/ResetMostRecentFocusOwnerTest.java

Print this page




   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      8013773
  28   @summary  Tests that disabled component is not retained as most recent focus owner.
  29   @author   Anton.Tarasov: area=awt.focus
  30   @library  ../../regtesthelpers
  31   @build    Util
  32   @run      main ResetMostRecentFocusOwnerTest
  33 */
  34 
  35 import java.applet.Applet;
  36 import java.awt.AWTEvent;
  37 import java.awt.FlowLayout;
  38 import java.awt.Robot;
  39 import java.awt.Toolkit;
  40 import java.awt.event.AWTEventListener;
  41 import java.awt.event.FocusEvent;
  42 import java.awt.event.WindowEvent;
  43 import javax.swing.JButton;
  44 import javax.swing.JFrame;
  45 import test.java.awt.regtesthelpers.Util;
  46 
  47 public class ResetMostRecentFocusOwnerTest extends Applet {
  48 
  49     public static void main(String[] args) {
  50         ResetMostRecentFocusOwnerTest app = new ResetMostRecentFocusOwnerTest();
  51         app.init();
  52         app.start();
  53     }
  54 
  55     @Override
  56     public void start() {
  57 
  58         Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
  59             public void eventDispatched(AWTEvent e) {
  60                 System.err.println(e);
  61             }
  62         }, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK);
  63 
  64         boolean gained = false;
  65         final Robot robot = Util.createRobot();
  66 
  67         JFrame frame1 = new JFrame("Main Frame");
  68         final JButton b1 = new JButton("button1");
  69         frame1.add(b1);
  70         frame1.pack();
  71         frame1.setLocation(0, 300);
  72 
  73         Util.showWindowWait(frame1);
  74 
  75         final JFrame frame2 = new JFrame("Test Frame");
  76         final JButton b2 = new JButton("button2");
  77         frame2.add(b2);
  78         frame2.pack();
  79         frame2.setLocation(300, 300);
  80 
  81         b2.setEnabled(false);
  82         b2.requestFocus();
  83 
  84         Util.showWindowWait(frame2);
  85 
  86         robot.delay(500);
  87 
  88         //
  89         // It's expeced that the focus is restored to <button1>.
  90         // If not, click <button1> to set focus on it.
  91         //




   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      8013773
  28   @summary  Tests that disabled component is not retained as most recent focus owner.

  29   @library  ../../regtesthelpers
  30   @build    Util
  31   @run      main ResetMostRecentFocusOwnerTest
  32 */
  33 

  34 import java.awt.AWTEvent;

  35 import java.awt.Robot;
  36 import java.awt.Toolkit;
  37 import java.awt.event.AWTEventListener;
  38 import java.awt.event.FocusEvent;
  39 import java.awt.event.WindowEvent;
  40 import javax.swing.JButton;
  41 import javax.swing.JFrame;
  42 import test.java.awt.regtesthelpers.Util;
  43 
  44 public class ResetMostRecentFocusOwnerTest {
  45 
  46     public static void main(String[] args) {
  47         ResetMostRecentFocusOwnerTest app = new ResetMostRecentFocusOwnerTest();

  48         app.start();
  49     }
  50 

  51     public void start() {
  52 
  53         Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
  54             public void eventDispatched(AWTEvent e) {
  55                 System.err.println(e);
  56             }
  57         }, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK);
  58 
  59         boolean gained = false;
  60         final Robot robot = Util.createRobot();
  61 
  62         JFrame frame1 = new JFrame("Main Frame");
  63         final JButton b1 = new JButton("button1");
  64         frame1.add(b1);
  65         frame1.pack();
  66         frame1.setLocation(100, 300);
  67 
  68         Util.showWindowWait(frame1);
  69 
  70         final JFrame frame2 = new JFrame("Test Frame");
  71         final JButton b2 = new JButton("button2");
  72         frame2.add(b2);
  73         frame2.pack();
  74         frame2.setLocation(300, 300);
  75 
  76         b2.setEnabled(false);
  77         b2.requestFocus();
  78 
  79         Util.showWindowWait(frame2);
  80 
  81         robot.delay(500);
  82 
  83         //
  84         // It's expeced that the focus is restored to <button1>.
  85         // If not, click <button1> to set focus on it.
  86         //


< prev index next >