< prev index next >

test/jdk/java/awt/Mouse/ExtraMouseClick/ExtraMouseClick.java

Print this page


   1 /*
   2  * Copyright (c) 2005, 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 5039416 6404008 7087869

  27   @summary REGRESSION: Extra mouse click dispatched after press-drag- release sequence.
  28   @library ../../regtesthelpers
  29   @build Util
  30   @author  andrei.dmitriev area=awt.event
  31   @run applet ExtraMouseClick.html
  32  */
  33 
  34 import java.applet.Applet;
  35 import java.awt.AWTException;
  36 import java.awt.BorderLayout;
  37 import java.awt.Frame;
  38 import java.awt.Point;
  39 import java.awt.Robot;
  40 import java.awt.Toolkit;
  41 import java.awt.event.InputEvent;
  42 import java.awt.event.MouseAdapter;
  43 import java.awt.event.MouseEvent;
  44 import java.awt.event.MouseMotionAdapter;
  45 import test.java.awt.regtesthelpers.Util;
  46 
  47 //**
  48 // Here are two values of smugde used in this test (2 and 5). They should be on
  49 // different sides from value 4 (smudge distance on both toolkits).
  50 // Note that this test may not fail easily. But it must always pass on
  51 // patched workspace.
  52 //**
  53 
  54 public class ExtraMouseClick extends Applet
  55 {
  56     Frame frame = new Frame("Extra Click After MouseDrag");
  57     final int TRIALS = 10;
  58     final int SMUDGE_WIDTH = 4;
  59     final int SMUDGE_HEIGHT = 4;
  60     Robot robot;
  61     Point fp; //frame's location on screen
  62     boolean dragged = false;
  63     boolean clicked = false;
  64     boolean pressed = false;
  65     boolean released = false;
  66 






  67     public void init()
  68     {
  69         this.setLayout (new BorderLayout ());
  70 
  71         frame.addMouseListener(new MouseAdapter() {
  72                 public void mousePressed(MouseEvent e) {
  73                     System.out.println("MousePressed");
  74                     pressed = true;
  75                 }
  76 
  77                 public void mouseReleased(MouseEvent e) {
  78                     System.out.println("MouseReleased");
  79                     released = true;
  80                 }
  81 
  82                 public void mouseClicked(MouseEvent e) {
  83                     System.out.println("MouseClicked!!!!");
  84                     clicked = true;
  85                 }
  86             });
  87         frame.addMouseMotionListener(new MouseMotionAdapter() {
  88                 public void mouseDragged(MouseEvent e) {
  89                     System.out.println("MouseDragged--"+e);
  90                     dragged = true;
  91                 }
  92                 public void mouseMoved(MouseEvent e) {
  93                 }
  94             });
  95 
  96     }//End  init()
  97 
  98 
  99     public void start ()
 100     {
 101         frame.setSize(480, 300);

 102         frame.setVisible(true);
 103         try{
 104             robot = new Robot();
 105         }catch(AWTException e){
 106             throw new RuntimeException(e);
 107         }
 108 
 109         Util.waitForIdle(robot);  //a time to show Frame
 110 
 111         fp = frame.getLocationOnScreen();
 112 
 113         for (int i = 0; i< TRIALS; i++){
 114             checkClicked();
 115             clearFlags();
 116         }
 117 
 118         for (int i = 0; i< TRIALS; i++){
 119             oneDrag(2);
 120             clearFlags();
 121         }


   1 /*
   2  * Copyright (c) 2005, 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 5039416 6404008
  28   @summary REGRESSION: Extra mouse click dispatched after press-drag- release sequence.
  29   @library ../../regtesthelpers
  30   @build Util
  31   @run main ExtraMouseClick

  32  */
  33 

  34 import java.awt.AWTException;

  35 import java.awt.Frame;
  36 import java.awt.Point;
  37 import java.awt.Robot;
  38 import java.awt.Toolkit;
  39 import java.awt.event.InputEvent;
  40 import java.awt.event.MouseAdapter;
  41 import java.awt.event.MouseEvent;
  42 import java.awt.event.MouseMotionAdapter;
  43 import test.java.awt.regtesthelpers.Util;
  44 
  45 //**
  46 // Here are two values of smugde used in this test (2 and 5). They should be on
  47 // different sides from value 4 (smudge distance on both toolkits).
  48 // Note that this test may not fail easily. But it must always pass on
  49 // patched workspace.
  50 //**
  51 public class ExtraMouseClick {


  52     Frame frame = new Frame("Extra Click After MouseDrag");
  53     final int TRIALS = 10;
  54     final int SMUDGE_WIDTH = 4;
  55     final int SMUDGE_HEIGHT = 4;
  56     Robot robot;
  57     Point fp; //frame's location on screen
  58     boolean dragged = false;
  59     boolean clicked = false;
  60     boolean pressed = false;
  61     boolean released = false;
  62 
  63     public static void main(final String[] args) {
  64         ExtraMouseClick app = new ExtraMouseClick();
  65         app.init();
  66         app.start();
  67     }
  68 
  69     public void init()
  70     {


  71         frame.addMouseListener(new MouseAdapter() {
  72                 public void mousePressed(MouseEvent e) {
  73                     System.out.println("MousePressed");
  74                     pressed = true;
  75                 }
  76 
  77                 public void mouseReleased(MouseEvent e) {
  78                     System.out.println("MouseReleased");
  79                     released = true;
  80                 }
  81 
  82                 public void mouseClicked(MouseEvent e) {
  83                     System.out.println("MouseClicked!!!!");
  84                     clicked = true;
  85                 }
  86             });
  87         frame.addMouseMotionListener(new MouseMotionAdapter() {
  88                 public void mouseDragged(MouseEvent e) {
  89                     System.out.println("MouseDragged--"+e);
  90                     dragged = true;
  91                 }
  92                 public void mouseMoved(MouseEvent e) {
  93                 }
  94             });
  95 
  96     }//End  init()
  97 
  98 
  99     public void start ()
 100     {
 101         frame.setSize(480, 300);
 102         frame.setLocationRelativeTo(null);
 103         frame.setVisible(true);
 104         try{
 105             robot = new Robot();
 106         }catch(AWTException e){
 107             throw new RuntimeException(e);
 108         }
 109 
 110         Util.waitForIdle(robot);  //a time to show Frame
 111 
 112         fp = frame.getLocationOnScreen();
 113 
 114         for (int i = 0; i< TRIALS; i++){
 115             checkClicked();
 116             clearFlags();
 117         }
 118 
 119         for (int i = 0; i< TRIALS; i++){
 120             oneDrag(2);
 121             clearFlags();
 122         }


< prev index next >