< prev index next >

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

Print this page




   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 MenuDragMouseEventAbsoluteCoordsTest.html

  30 */
  31 
  32 import java.applet.Applet;
  33 import java.awt.*;
  34 import javax.swing.event.*;
  35 import java.awt.event.*;
  36 import javax.swing.MenuSelectionManager;
  37 import javax.swing.MenuElement;
  38 import test.java.awt.regtesthelpers.Util;
  39 
  40 // The test consits of several parts:
  41 // 1. create MenuDragMouseEvent with new Ctor and checking get(X|Y)OnScreen(),
  42 // getLocationOnScreen(), get(X|Y), getPoint().
  43 // 2. create MenuDragMouseEvent with old Ctor and checking get(X|Y)OnScreen(),
  44 // getLocationOnScreen(),  get(X|Y), getPoint() .
  45 
  46 
  47 public class MenuDragMouseEventAbsoluteCoordsTest extends Applet implements MouseListener
  48 {
  49     Frame frame = new Frame("MenuDragMouseEvent Test Frame");
  50 
  51     Point mousePositionOnScreen = new Point(200, 200);
  52     Point mousePosition = new Point(100, 100);







  53     public void init()
  54     {
  55         frame.addMouseListener(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.setVisible(true);
  63         validate();
  64 
  65         try {
  66             Util.waitForIdle(new Robot());
  67         }catch (Exception e){
  68             throw new RuntimeException("Test failed.", e);
  69         }
  70 
  71         // use new MenuDragMouseEvent's Ctor with user-defined absolute
  72         // coordinates
  73 
  74         System.out.println("New Ctor Stage MOUSE_PRESSED");
  75         postMenuDragMouseEventNewCtor(MouseEvent.MOUSE_PRESSED);
  76         // now we are going to use old MenuDragMouseEvent's Ctor thus absolute
  77         // position calculates as frame's location + relative coords
  78         // of the event.
  79         mousePositionOnScreen = new Point(frame.getLocationOnScreen().x + mousePosition.x,
  80                                           frame.getLocationOnScreen().y + mousePosition.y);
  81 
  82         System.out.println("Old Ctor Stage MOUSE_PRESSED");
  83         postMenuDragMouseEventOldCtor(MouseEvent.MOUSE_PRESSED);




   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 MenuDragMouseEventAbsoluteCoordsTest
  32 */
  33 

  34 import java.awt.*;
  35 import javax.swing.event.*;
  36 import java.awt.event.*;


  37 import test.java.awt.regtesthelpers.Util;
  38 
  39 // The test consits of several parts:
  40 // 1. create MenuDragMouseEvent with new Ctor and checking get(X|Y)OnScreen(),
  41 // getLocationOnScreen(), get(X|Y), getPoint().
  42 // 2. create MenuDragMouseEvent with old Ctor and checking get(X|Y)OnScreen(),
  43 // getLocationOnScreen(),  get(X|Y), getPoint() .
  44 
  45 
  46 public class MenuDragMouseEventAbsoluteCoordsTest implements MouseListener
  47 {
  48     Frame frame = new Frame("MenuDragMouseEvent Test Frame");
  49 
  50     Point mousePositionOnScreen = new Point(200, 200);
  51     Point mousePosition = new Point(100, 100);
  52 
  53     public static void main(String[] args) {
  54         MenuDragMouseEventAbsoluteCoordsTest app = new MenuDragMouseEventAbsoluteCoordsTest();
  55         app.init();
  56         app.start();
  57     }
  58 
  59     public void init()
  60     {
  61         frame.addMouseListener(this);
  62     }//End  init()
  63 
  64     public void start ()
  65     {
  66         //Get things going.  Request focus, set size, et cetera
  67         frame.setSize (200,200);
  68         frame.setVisible(true);

  69 
  70         try {
  71             Util.waitForIdle(new Robot());
  72         }catch (Exception e){
  73             throw new RuntimeException("Test failed.", e);
  74         }
  75 
  76         // use new MenuDragMouseEvent's Ctor with user-defined absolute
  77         // coordinates
  78 
  79         System.out.println("New Ctor Stage MOUSE_PRESSED");
  80         postMenuDragMouseEventNewCtor(MouseEvent.MOUSE_PRESSED);
  81         // now we are going to use old MenuDragMouseEvent'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 
  87         System.out.println("Old Ctor Stage MOUSE_PRESSED");
  88         postMenuDragMouseEventOldCtor(MouseEvent.MOUSE_PRESSED);


< prev index next >