java/awt/Choice/GrabLockTest/GrabLockTest.java

Print this page


   1 /*
   2   test






















   3   @bug 4800638
   4   @summary Tests that Choice does not lock the Desktop
   5   @run applet GrabLockTest.html
   6 */
   7 import java.applet.Applet;
   8 import java.awt.*;
   9 import java.awt.event.*;
  10 import sun.awt.SunToolkit;
  11 
  12 public class GrabLockTest extends Applet
  13 {
  14     //Declare things used in the test, like buttons and labels here
  15 
  16     public void init()
  17     {
  18     }//End  init()
  19 
  20     public void start ()
  21     {
  22         Frame frame = new TestFrame();
  23     }
  24 }
  25 
  26 class TestFrame extends Frame implements MouseListener {
  27     public TestFrame() {
  28         Choice choice = new Choice();
  29         choice.addItem("Fist Item");
  30         choice.addItem("Second Item");
  31         add(choice,BorderLayout.NORTH);
  32         Panel panel = new Panel();
  33         panel.addMouseListener(this);
  34         panel.setBackground(Color.RED);
  35         add(panel);
  36         setSize(200, 200);
  37         setVisible(true);
  38         toFront();
  39 
  40         try {
  41             Robot robot = new Robot();
  42             robot.setAutoWaitForIdle(true);
  43             robot.setAutoDelay(50);
  44 
  45             ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
  46 
  47             Point pt = choice.getLocationOnScreen();
  48             robot.mouseMove(pt.x + choice.getWidth() - choice.getHeight()/2,
  49                 pt.y + choice.getHeight()/2);
  50             robot.mousePress(InputEvent.BUTTON1_MASK);
  51             ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
  52             robot.mouseMove(pt.x + choice.getWidth()/2,
  53                 pt.y + choice.getHeight()*2);
  54             ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
  55             robot.mousePress(InputEvent.BUTTON2_MASK);
  56             ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
  57             Point pt1 = panel.getLocationOnScreen();
  58             robot.mouseMove(pt1.x + panel.getWidth()/2,
  59                 pt1.y + panel.getHeight()/2);
  60             ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
  61             robot.mouseRelease(InputEvent.BUTTON1_MASK);
  62             robot.mouseRelease(InputEvent.BUTTON2_MASK);
  63 
  64             ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
  65 
  66             robot.mousePress(InputEvent.BUTTON1_MASK);
  67             robot.delay(30);
  68             robot.mouseRelease(InputEvent.BUTTON1_MASK);
  69             ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
  70             if (nPressed == 0) {
  71                 robot.keyPress(KeyEvent.VK_ESCAPE);
  72                 robot.keyRelease(KeyEvent.VK_ESCAPE);
  73                 throw new RuntimeException("GrabLockTest failed." + nPressed);
  74             }
  75         } catch (Exception e) {
  76             throw new RuntimeException("The test was not completed.\n\n" + e);
  77         }
  78 
  79     }// start()
  80 
  81     public int nPressed = 0;
  82 
  83     public void mouseClicked(MouseEvent e) {
  84     }
  85 
  86     public void mousePressed(MouseEvent e) {
  87         nPressed++;
  88         System.out.println("Pressed!");
  89     }
  90 
  91     public void mouseReleased(MouseEvent e) {
  92     }
  93 
  94     public void mouseEntered(MouseEvent e) {}
  95     public void mouseExited(MouseEvent e) {}
  96 }// class TestFrame
   1 /*
   2  * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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   @test
  25   @bug 4800638
  26   @summary Tests that Choice does not lock the Desktop
  27   @run main GrabLockTest
  28 */

  29 import java.awt.*;
  30 import java.awt.event.*;

  31 
  32 public class GrabLockTest 
  33 {
  34     public static void main (String args[])






  35     {
  36         Frame frame = new TestFrame();
  37     }
  38 }
  39 
  40 class TestFrame extends Frame implements MouseListener {
  41     public TestFrame() {
  42         Choice choice = new Choice();
  43         choice.addItem("Fist Item");
  44         choice.addItem("Second Item");
  45         add(choice,BorderLayout.NORTH);
  46         Panel panel = new Panel();
  47         panel.addMouseListener(this);
  48         panel.setBackground(Color.RED);
  49         add(panel);
  50         setSize(200, 200);
  51         setVisible(true);
  52         toFront();
  53 
  54         try {
  55             Robot robot = new Robot();
  56             robot.setAutoWaitForIdle(true);
  57             robot.setAutoDelay(50);
  58 
  59             robot.waitForIdle();
  60 
  61             Point pt = choice.getLocationOnScreen();
  62             robot.mouseMove(pt.x + choice.getWidth() - choice.getHeight()/2,
  63                 pt.y + choice.getHeight()/2);
  64             robot.mousePress(InputEvent.BUTTON1_MASK);
  65             robot.waitForIdle();
  66             robot.mouseMove(pt.x + choice.getWidth()/2,
  67                 pt.y + choice.getHeight()*2);
  68             robot.waitForIdle();
  69             robot.mousePress(InputEvent.BUTTON2_MASK);
  70             robot.waitForIdle();
  71             Point pt1 = panel.getLocationOnScreen();
  72             robot.mouseMove(pt1.x + panel.getWidth()/2,
  73                 pt1.y + panel.getHeight()/2);
  74             robot.waitForIdle();
  75             robot.mouseRelease(InputEvent.BUTTON1_MASK);
  76             robot.mouseRelease(InputEvent.BUTTON2_MASK);
  77 
  78             robot.waitForIdle();
  79 
  80             robot.mousePress(InputEvent.BUTTON1_MASK);
  81             robot.delay(30);
  82             robot.mouseRelease(InputEvent.BUTTON1_MASK);
  83             robot.waitForIdle();
  84             if (nPressed == 0) {
  85                 robot.keyPress(KeyEvent.VK_ESCAPE);
  86                 robot.keyRelease(KeyEvent.VK_ESCAPE);
  87                 throw new RuntimeException("GrabLockTest failed." + nPressed);
  88             }
  89         } catch (Exception e) {
  90             throw new RuntimeException("The test was not completed.\n\n" + e);
  91         }
  92 
  93     }
  94 
  95     public int nPressed = 0;
  96 
  97     public void mouseClicked(MouseEvent e) {
  98     }
  99 
 100     public void mousePressed(MouseEvent e) {
 101         nPressed++;
 102         System.out.println("Pressed!");
 103     }
 104 
 105     public void mouseReleased(MouseEvent e) {
 106     }
 107 
 108     public void mouseEntered(MouseEvent e) {}
 109     public void mouseExited(MouseEvent e) {}
 110 }// class TestFrame