< prev index next >

test/jdk/java/awt/event/MouseEvent/FrameMouseEventAbsoluteCoordsTest/FrameMouseEventAbsoluteCoordsTest.java

Print this page


   1 /*
   2  * Copyright (c) 2004, 2006, 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 /*
  25   test

  26   @bug 4992908
  27   @summary Need way to get location of MouseEvent in screen  coordinates (Unit-test)
  28   @author Andrei.Dmitriev area=event
  29   @run applet FrameMouseEventAbsoluteCoordsTest.html

  30 */
  31 
  32 import java.applet.Applet;
  33 import java.awt.*;
  34 import java.awt.event.*;
  35 import test.java.awt.regtesthelpers.Util;
  36 
  37 // Part II
  38 // Create Frame.
  39 // Click on this frame.
  40 // verify that our MouseEvent contain correct xAbs, yAbs values
  41 
  42 public class FrameMouseEventAbsoluteCoordsTest extends Applet implements MouseListener
  43 {
  44     Robot robot;
  45     Frame frame = new Frame("MouseEvent Test Frame II");
  46     Button button = new Button("Just Button");
  47     Point mousePositionAbsolute;
  48     Point mousePosition;
  49 






  50     public void init()
  51     {
  52 
  53         this.setLayout (new BorderLayout ());
  54         button.addMouseListener(this);
  55         frame.add(button);
  56         frame.pack();

  57     }//End  init()
  58 
  59     public void start ()
  60     {
  61         setSize (200,200);
  62         frame.setVisible(true);
  63         validate();
  64         Util.waitForIdle(robot);
  65 
  66         try {
  67             robot = new Robot();
  68             robot.setAutoWaitForIdle(true);
  69             mousePositionAbsolute = new Point(button.getLocationOnScreen().x + button.getWidth()/2,
  70                                               button.getLocationOnScreen().y + button.getHeight()/2);
  71             mousePosition = new Point(button.getWidth()/2,
  72                                       button.getHeight()/2);
  73             robot.mouseMove(mousePositionAbsolute.x,
  74                             mousePositionAbsolute.y );
  75             //            robot.delay(1000);
  76             robot.mousePress(InputEvent.BUTTON1_MASK);
  77             robot.mouseRelease(InputEvent.BUTTON1_MASK);
  78         }catch(AWTException e) {
  79             throw new RuntimeException("Test Failed. AWTException thrown.");
  80         }
  81     }// start()
  82 
  83     public void mousePressed(MouseEvent e){


   1 /*
   2  * Copyright (c) 2004, 2018, 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 /*
  25   @test
  26   @key headful
  27   @bug 4992908
  28   @summary Need way to get location of MouseEvent in screen  coordinates (Unit-test)
  29   @library ../../../regtesthelpers
  30   @build Util
  31   @run main FrameMouseEventAbsoluteCoordsTest
  32 */
  33 

  34 import java.awt.*;
  35 import java.awt.event.*;
  36 import test.java.awt.regtesthelpers.Util;
  37 
  38 // Part II
  39 // Create Frame.
  40 // Click on this frame.
  41 // verify that our MouseEvent contain correct xAbs, yAbs values
  42 
  43 public class FrameMouseEventAbsoluteCoordsTest implements MouseListener
  44 {
  45     Robot robot;
  46     Frame frame = new Frame("MouseEvent Test Frame II");
  47     Button button = new Button("Just Button");
  48     Point mousePositionAbsolute;
  49     Point mousePosition;
  50 
  51     public static void main(final String[] args) {
  52         FrameMouseEventAbsoluteCoordsTest app = new FrameMouseEventAbsoluteCoordsTest();
  53         app.init();
  54         app.start();
  55     }
  56 
  57     public void init()
  58     {


  59         button.addMouseListener(this);
  60         frame.add(button);
  61         frame.pack();
  62         frame.setLocationRelativeTo(null);
  63     }//End  init()
  64 
  65     public void start ()
  66     {

  67         frame.setVisible(true);

  68         Util.waitForIdle(robot);
  69 
  70         try {
  71             robot = new Robot();
  72             robot.setAutoWaitForIdle(true);
  73             mousePositionAbsolute = new Point(button.getLocationOnScreen().x + button.getWidth()/2,
  74                                               button.getLocationOnScreen().y + button.getHeight()/2);
  75             mousePosition = new Point(button.getWidth()/2,
  76                                       button.getHeight()/2);
  77             robot.mouseMove(mousePositionAbsolute.x,
  78                             mousePositionAbsolute.y );
  79             //            robot.delay(1000);
  80             robot.mousePress(InputEvent.BUTTON1_MASK);
  81             robot.mouseRelease(InputEvent.BUTTON1_MASK);
  82         }catch(AWTException e) {
  83             throw new RuntimeException("Test Failed. AWTException thrown.");
  84         }
  85     }// start()
  86 
  87     public void mousePressed(MouseEvent e){


< prev index next >