-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.1.5, 1.2.0, 1.2.2, 1.3.0
-
generic, x86, sparc
-
generic, solaris_2.5.1, windows_nt
I'd like to have two separate methods get executed based on click count. Like this:
public void mouseClicked(MouseEvent e)
{
System.out.println("debug: \t\t\tmouseClicked: (" + e.getX() + ", " +
e.getY() + ") ");
System.out.println("debug: \t\t\tmouseClicked point: (" + e.getPoint() + ")");
switch (e.getClickCount()) {
case 1:
this.singleClick(e);
break;
case 2:
this.doubleClick(e);
break;
}
}
However, when I double click, mouseClicked() gets called twice, once with a clickCount of 1 and then with a clickCount of 2. I would think it would only get called once. Here is a simple program (dependent on swing 0.4.1 for the frame and other things not of importance to this testcase). You must put
/net/lighthome.eng/export/java/swing-latest/swing.jar in your classpath to compile this. If you don't want to compile it, the runnable class MouseTest is at in /net/arago.eng/ProjectsLocal/edburns/scratch/
Here's the code
// Copyright 1997 Lighthouse Design, Ltd. All rights reserved.
// CONFIDENTIAL
// MouseTest.java
/**
* <B>MouseTest</B> is a simple class that has a main. Used to test things.
* in libraries;
*
* @version $Id: MouseTest.java,v 1.40 1997/03/03 18:46:52 edburns Exp $
*
*
*/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.WindowAdapter;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseEvent;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import com.sun.java.swing.JFrame;
import com.sun.java.swing.JBufferedPane;
import com.sun.java.swing.UIManager;
public class MouseTest extends JBufferedPane implements MouseMotionListener,
MouseListener
{
//
// Protected Constants
//
static protected int WIDTH = 500;
static protected int HEIGHT = 400;
static protected String TITLE = "MouseTest";
//
// Class Variables
//
static protected MouseTest instance = null;
static protected JFrame frame = null;
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public MouseTest()
{
super();
}
static public MouseTest instance()
{
if (null == MouseTest.instance) {
MouseTest.instance = new MouseTest();
}
return MouseTest.instance;
}
//
// General Methods
//
static public void main(String args[])
{
MouseTest me = MouseTest.instance();
frame = new JFrame(MouseTest.TITLE);
frame.setForeground(Color.black);
frame.setForeground(Color.lightGray);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
try {
UIManager.setUIFactory(
"com.sun.java.swing.basic.BasicFactory", frame);
} catch (ClassNotFoundException cnf) {
}
Dimension screenSize, initialSize = new Dimension(WIDTH, HEIGHT);
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setSize(initialSize);
frame.setLocation(screenSize.width/2 - initialSize.width/2,
screenSize.height/2 - initialSize.height/2);
frame.add(me);
frame.show();
me.setPreferredSize(new Dimension(WIDTH/2, HEIGHT/2));
me.setBounds(WIDTH/4, HEIGHT/4, WIDTH/2, HEIGHT/2);
me.setBackground(Color.red);
me.addMouseListener(me);
me.addMouseMotionListener(me);
}
//
// Methods from Componont
//
//
// Methods from MouseMotionListener
//
public void mouseDragged(MouseEvent e)
{
System.out.println("debug: mouseDragged: (" + e.getX() + ", " +
e.getY() + ") ");
System.out.println("debug: mouseDragged point: (" + e.getPoint() + ")");
}
public void mouseMoved(MouseEvent e)
{
System.out.println("debug: \t\t\tmouseMoved: (" + e.getX() + ", " +
e.getY() + ") ");
System.out.println("debug: \t\t\tmouseMoved point: (" + e.getPoint() + ")");
}
//
// Methods from Mouseistener
//
public void mouseClicked(MouseEvent e)
{
System.out.println("debug: \t\t\tmouseClicked: (" + e.getX() + ", " +
e.getY() + ") ");
System.out.println("debug: \t\t\tmouseClicked point: (" + e.getPoint() + ")");
switch (e.getClickCount()) {
case 1:
this.singleClick(e);
break;
case 2:
this.doubleClick(e);
break;
}
}
public void singleClick(MouseEvent e)
{
System.out.println("debug: singleClick");
}
public void doubleClick(MouseEvent e)
{
System.out.println("debug: doubleClick");
}
public void mousePressed(MouseEvent e)
{
System.out.println("debug: \t\t\tmousePressed: (" + e.getX() + ", " +
e.getY() + ") ");
System.out.println("debug: \t\t\tmousePressed point: (" + e.getPoint() + ")");
if (e.isAltDown()) {
System.out.println("debug: \t\t\tmousePressed with Alt");
}
if (e.isControlDown()) {
System.out.println("debug: \t\t\tmousePressed with Control");
}
if (e.isMetaDown()) {
System.out.println("debug: \t\t\tmousePressed with Meta");
}
if (e.isShiftDown()) {
System.out.println("debug: \t\t\tmousePressed with Shift");
}
}
public void mouseReleased(MouseEvent e)
{
System.out.println("debug: \t\t\tmouseReleased: (" + e.getX() + ", " +
e.getY() + ") ");
System.out.println("debug: \t\t\tmouseReleased point: (" + e.getPoint() + ")");
}
public void mouseEntered(MouseEvent e)
{
System.out.println("debug: \t\t\tmouseEntered: (" + e.getX() + ", " +
e.getY() + ") ");
System.out.println("debug: \t\t\tmouseEntered point: (" + e.getPoint() + ")");
}
public void mouseExited(MouseEvent e)
{
System.out.println("debug: \t\t\tmouseExited: (" + e.getX() + ", " +
e.getY() + ") ");
System.out.println("debug: \t\t\tmouseExited point: (" + e.getPoint() + ")");
}
} // end of class MouseTest
public void mouseClicked(MouseEvent e)
{
System.out.println("debug: \t\t\tmouseClicked: (" + e.getX() + ", " +
e.getY() + ") ");
System.out.println("debug: \t\t\tmouseClicked point: (" + e.getPoint() + ")");
switch (e.getClickCount()) {
case 1:
this.singleClick(e);
break;
case 2:
this.doubleClick(e);
break;
}
}
However, when I double click, mouseClicked() gets called twice, once with a clickCount of 1 and then with a clickCount of 2. I would think it would only get called once. Here is a simple program (dependent on swing 0.4.1 for the frame and other things not of importance to this testcase). You must put
/net/lighthome.eng/export/java/swing-latest/swing.jar in your classpath to compile this. If you don't want to compile it, the runnable class MouseTest is at in /net/arago.eng/ProjectsLocal/edburns/scratch/
Here's the code
// Copyright 1997 Lighthouse Design, Ltd. All rights reserved.
// CONFIDENTIAL
// MouseTest.java
/**
* <B>MouseTest</B> is a simple class that has a main. Used to test things.
* in libraries;
*
* @version $Id: MouseTest.java,v 1.40 1997/03/03 18:46:52 edburns Exp $
*
*
*/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.WindowAdapter;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseEvent;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import com.sun.java.swing.JFrame;
import com.sun.java.swing.JBufferedPane;
import com.sun.java.swing.UIManager;
public class MouseTest extends JBufferedPane implements MouseMotionListener,
MouseListener
{
//
// Protected Constants
//
static protected int WIDTH = 500;
static protected int HEIGHT = 400;
static protected String TITLE = "MouseTest";
//
// Class Variables
//
static protected MouseTest instance = null;
static protected JFrame frame = null;
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public MouseTest()
{
super();
}
static public MouseTest instance()
{
if (null == MouseTest.instance) {
MouseTest.instance = new MouseTest();
}
return MouseTest.instance;
}
//
// General Methods
//
static public void main(String args[])
{
MouseTest me = MouseTest.instance();
frame = new JFrame(MouseTest.TITLE);
frame.setForeground(Color.black);
frame.setForeground(Color.lightGray);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
try {
UIManager.setUIFactory(
"com.sun.java.swing.basic.BasicFactory", frame);
} catch (ClassNotFoundException cnf) {
}
Dimension screenSize, initialSize = new Dimension(WIDTH, HEIGHT);
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setSize(initialSize);
frame.setLocation(screenSize.width/2 - initialSize.width/2,
screenSize.height/2 - initialSize.height/2);
frame.add(me);
frame.show();
me.setPreferredSize(new Dimension(WIDTH/2, HEIGHT/2));
me.setBounds(WIDTH/4, HEIGHT/4, WIDTH/2, HEIGHT/2);
me.setBackground(Color.red);
me.addMouseListener(me);
me.addMouseMotionListener(me);
}
//
// Methods from Componont
//
//
// Methods from MouseMotionListener
//
public void mouseDragged(MouseEvent e)
{
System.out.println("debug: mouseDragged: (" + e.getX() + ", " +
e.getY() + ") ");
System.out.println("debug: mouseDragged point: (" + e.getPoint() + ")");
}
public void mouseMoved(MouseEvent e)
{
System.out.println("debug: \t\t\tmouseMoved: (" + e.getX() + ", " +
e.getY() + ") ");
System.out.println("debug: \t\t\tmouseMoved point: (" + e.getPoint() + ")");
}
//
// Methods from Mouseistener
//
public void mouseClicked(MouseEvent e)
{
System.out.println("debug: \t\t\tmouseClicked: (" + e.getX() + ", " +
e.getY() + ") ");
System.out.println("debug: \t\t\tmouseClicked point: (" + e.getPoint() + ")");
switch (e.getClickCount()) {
case 1:
this.singleClick(e);
break;
case 2:
this.doubleClick(e);
break;
}
}
public void singleClick(MouseEvent e)
{
System.out.println("debug: singleClick");
}
public void doubleClick(MouseEvent e)
{
System.out.println("debug: doubleClick");
}
public void mousePressed(MouseEvent e)
{
System.out.println("debug: \t\t\tmousePressed: (" + e.getX() + ", " +
e.getY() + ") ");
System.out.println("debug: \t\t\tmousePressed point: (" + e.getPoint() + ")");
if (e.isAltDown()) {
System.out.println("debug: \t\t\tmousePressed with Alt");
}
if (e.isControlDown()) {
System.out.println("debug: \t\t\tmousePressed with Control");
}
if (e.isMetaDown()) {
System.out.println("debug: \t\t\tmousePressed with Meta");
}
if (e.isShiftDown()) {
System.out.println("debug: \t\t\tmousePressed with Shift");
}
}
public void mouseReleased(MouseEvent e)
{
System.out.println("debug: \t\t\tmouseReleased: (" + e.getX() + ", " +
e.getY() + ") ");
System.out.println("debug: \t\t\tmouseReleased point: (" + e.getPoint() + ")");
}
public void mouseEntered(MouseEvent e)
{
System.out.println("debug: \t\t\tmouseEntered: (" + e.getX() + ", " +
e.getY() + ") ");
System.out.println("debug: \t\t\tmouseEntered point: (" + e.getPoint() + ")");
}
public void mouseExited(MouseEvent e)
{
System.out.println("debug: \t\t\tmouseExited: (" + e.getX() + ", " +
e.getY() + ") ");
System.out.println("debug: \t\t\tmouseExited point: (" + e.getPoint() + ")");
}
} // end of class MouseTest