dcsimg
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Intermediate
Mar 16, 1999

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Detecting Double-Clicks

When creating a Java GUI, it is often the case that you want some action to be taken when the user double-clicks on some component. Although there is no simple way to detect double-clicks in Java 1.0.2, the new 1.1 event model provides an easy way to do this. Simply call the getClickCount() method on the instance of the MouseEvent class that is passed to the mouseClicked() or mousePressed() methods which are part of the MouseListener interface. When a value of 2 is returned from getClickCount(), this indicates that the user has double-clicked on the component. For example:
 
import java.awt.*;
import java.awt.event.*;

public class DoubleClickTest extends Panel implements MouseListener {

	public void mousePressed(MouseEvent event) {
		if (event.getClickCount() == 2) {
			//  Executed only when the user double-clicks on
this component
			System.out.println("User double-clicked");
		}  //  if (event.getClickCount() == 2)
	}  //  public void mousePressed()

	public void mouseReleased(MouseEvent event) {};
	public void mouseEntered(MouseEvent event) {};
	public void mouseExited(MouseEvent event) {};
	public void mouseClicked(MouseEvent event) {};

}  //  public class DoubleClickTest extends Panel implements MouseListener
()
Brett Spell
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date