With the timer delay to achieve the mouse double click event events, click and double-click events independently of each other!

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Date;
import java.util.Timer;

 *  Use the timer delay click event implements mouse double-click event  , Click and double-click event from interfering with each other  !
public class UserMouseAdapter extends MouseAdapter {

        private boolean flag = false;//  Use to determine whether has been executed the double-click event
        private int clickNum = 0;//  Use to determine whether the execution double-click event  

        public void mouseClicked(MouseEvent e) {
                final MouseEvent me = e;//  The event source  

                this.flag = false;//  Each click of the mouse initialization double-click event flag to false  

                if (this.clickNum == 1) {//  When clickNum  ==1 When you perform a double-click event
                        this.mouseDoubleClicked(me);//  Perform a double-click event
                        this.clickNum = 0;//  Initializes a double-click event flag to 0
                        this.flag = true;//  Double-click the event have already been performed  , Event flag to true

                //  Define the timer
                Timer timer = new Timer();

                //  Timer start  , Delay-0  .2 Seconds after the click event
                timer.schedule(new java.util.TimerTask() {
                        private int n = 0;//  Record timer executions  

                        public void run() {
                                if (flag) {//  If you double-click event has executed  , Then click the perform directly cancel
                                        n = 0;
                                        clickNum = 0;
                                if (n == 1) {//  Timer wait 0  .2 Seconds  , Double-click the event has not yet happened  , Perform the click event
                                        mouseSingleClicked(me);//  Perform the click event
                                        flag = true;
                                        clickNum = 0;
                                        n = 0;
                }, new Date(), 200); //  To set the delay time

        /** */
         *  The mouse click event
         * @param e
         *             The event source parameters
        public void mouseSingleClicked(MouseEvent e) {
                // System.out.println("Single Clicked!");

        /** */
         *  Mouse double-click event
         * @param e
         *             The event source parameters
        public void mouseDoubleClicked(MouseEvent e) {
                // System.out.println("Doublc Clicked!");
分类:Java 时间:2010-03-29 人气:539
blog comments powered by Disqus


  • Double-click to run java 2010-12-18

    Following is a brief look at production methods: First, write a java class of the simple import javax.swing .*; public class MyFrame { public static void main (String [] args) { JFrame fr = new JFrame (); fr.setSize (300,300); fr.show (); } } The lat

  • (Original) Java timer: java.util.Timer 2010-11-25

    java.util.Timer time in the program can achieve the task, Timer and implementation classes need to inherit java.util.TimerTask the run () method, in fact, is an abstract class TimerTask, he inherited the java.lang.Runnable interface. package yehaizi.

  • Java language, Calendar and Date classes 2010-03-29

    Java-Calendar (calendar), Date (date), and DateFormat (date format) to form a basic Java standard but very important part. Business logic to calculate the date is a key part. All the developers should be able to calculate a future date, custom date d

  • java to operate the date type 2010-03-05

    In JDK 1.1, after, java.util.Date type of most of the methods have not recommended use. Instead it is the Calendar. In between java.sql.Date and java.util.Date, and some subtle relationship. How to Date type into a database, a lot of people in a no s

  • java convert string to date type 2010-08-24

    String date = "2006-11-23" SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd"); java.util.Date cDate = df.parse (date); java.sql.Date dd = new java.sql.Date (cDate.getTime ()); System.out.println ("converted date =" + d

  • JAVA string to SQL date 2011-07-23

    / / Inorder to get the SQL Date type like date, use the following steps: String date = "2007-11-23" SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd"); java.util.Date Date = df.parse (date); java.sql.Date formatDate = new java.s

  • flex and java how communication with the public session webService 2010-12-26

    flex and java how communication with the public session webService This is very troublesome, because you have to be very understanding of what session which in the end (as to flex there, not so strict over there in java) The correct approach is, java

  • Some rights java modifiers, private / friendly / protected / public 2010-05-29

    Begin testing the following: A Test class, as was access to the class, private not say, can access only its own, public is able to access, this is mainly to distinguish between friendly and protected New two classes, Test1 and Test2 to visit Test, Te

  • Add right-click menu: Compile java file 2010-11-19

    Compile all the java classes folder files: Save the following code to folderJavac.reg Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT \ Folder \ shell \ javac] @ = "Javac compile directory (& B)" [HKEY_CLASSES_ROOT \ Folder \ shell \

  • Double click a button to install - Java installation program production 2011-04-22

    Double click a button to install - Java installation program production Title: A double-click the Run button to install - Java installation program made of: Jason Du Time: 2009-3-23 Original: http://www.blogjava.net/javapro/archive/2009/03/24/JavaApp

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.406 (s). 12 q(s)