< prev index next >

test/jdk/java/awt/event/MouseEvent/MouseWheelEventAbsoluteCoordsTest/MouseWheelEventAbsoluteCoordsTest.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
  28   @author Andrei.Dmitriev area=event
  29   @run applet MouseWheelEventAbsoluteCoordsTest.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 // The test consits of several parts:
  38 // 1. create MouseWheelEvent with new Ctor and checking get(X|Y)OnScreen(),
  39 // getLocationOnScreen(), get(X|Y), getPoint().
  40 // 2. create MouseWheelEvent with old Ctor and checking get(X|Y)OnScreen(),
  41 // getLocationOnScreen(),  get(X|Y), getPoint() .
  42 
  43 
  44 public class MouseWheelEventAbsoluteCoordsTest extends Applet implements MouseWheelListener
  45 {
  46     Frame frame = new Frame("MouseWheelEvent Test Frame");
  47 
  48     Point mousePositionOnScreen = new Point(200, 200);
  49     Point mousePosition = new Point(100, 100);
  50     public void init()
  51     {
  52 
  53         this.setLayout (new BorderLayout ());




  54 


  55         frame.addMouseWheelListener(this);
  56     }//End  init()
  57 
  58     public void start ()
  59     {
  60         //Get things going.  Request focus, set size, et cetera
  61         frame.setSize (200,200);
  62         frame.setLocation(47, 47);
  63 
  64         frame.setVisible(true);
  65         validate();
  66         try {
  67             Util.waitForIdle(new Robot());
  68         }catch (Exception e){
  69             throw new RuntimeException("Test failed.", e);
  70         }
  71 
  72         // use new MouseEvent's Ctor with user-defined absolute
  73         // coordinates
  74         System.out.println("New Ctor Stage");
  75         postMouseWheelEventNewCtor(MouseEvent.MOUSE_CLICKED);
  76 
  77         // now we gonna use old MouseEvent's Ctor thus absolute
  78         // position calculates as frame's location + relative coords
  79         // of the event.
  80         mousePositionOnScreen = new Point(frame.getLocationOnScreen().x + mousePosition.x,
  81                                           frame.getLocationOnScreen().y + mousePosition.y);
  82         System.out.println("Old Ctor Stage");
  83         postMouseWheelEventOldCtor(MouseEvent.MOUSE_CLICKED);
  84 
  85     }// start()


   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
  29   @library ../../../regtesthelpers
  30   @build Util
  31   @run main MouseWheelEventAbsoluteCoordsTest
  32 */
  33 

  34 import java.awt.*;
  35 import java.awt.event.*;
  36 import test.java.awt.regtesthelpers.Util;
  37 
  38 // The test consits of several parts:
  39 // 1. create MouseWheelEvent with new Ctor and checking get(X|Y)OnScreen(),
  40 // getLocationOnScreen(), get(X|Y), getPoint().
  41 // 2. create MouseWheelEvent with old Ctor and checking get(X|Y)OnScreen(),
  42 // getLocationOnScreen(),  get(X|Y), getPoint() .
  43 
  44 
  45 public class MouseWheelEventAbsoluteCoordsTest implements MouseWheelListener
  46 {
  47     Frame frame = new Frame("MouseWheelEvent Test Frame");
  48 
  49     Point mousePositionOnScreen = new Point(200, 200);
  50     Point mousePosition = new Point(100, 100);


  51 
  52     public static void main(final String[] args) {
  53         MouseWheelEventAbsoluteCoordsTest app = new MouseWheelEventAbsoluteCoordsTest();
  54         app.init();
  55         app.start();
  56     }
  57 
  58     public void init()
  59     {
  60         frame.addMouseWheelListener(this);
  61     }//End  init()
  62 
  63     public void start ()
  64     {
  65         //Get things going.  Request focus, set size, et cetera
  66         frame.setSize (200,200);
  67         frame.setLocation(47, 47);
  68 
  69         frame.setVisible(true);

  70         try {
  71             Util.waitForIdle(new Robot());
  72         }catch (Exception e){
  73             throw new RuntimeException("Test failed.", e);
  74         }
  75 
  76         // use new MouseEvent's Ctor with user-defined absolute
  77         // coordinates
  78         System.out.println("New Ctor Stage");
  79         postMouseWheelEventNewCtor(MouseEvent.MOUSE_CLICKED);
  80 
  81         // now we gonna use old MouseEvent's Ctor thus absolute
  82         // position calculates as frame's location + relative coords
  83         // of the event.
  84         mousePositionOnScreen = new Point(frame.getLocationOnScreen().x + mousePosition.x,
  85                                           frame.getLocationOnScreen().y + mousePosition.y);
  86         System.out.println("Old Ctor Stage");
  87         postMouseWheelEventOldCtor(MouseEvent.MOUSE_CLICKED);
  88 
  89     }// start()


< prev index next >