Results 1 to 5 of 5
  1. #1
    mitra is offline Member
    Join Date
    Jun 2011
    Posts
    59
    Rep Power
    0

    Default getClickCount() problem within mouseClicked method

    Hi guys.....

    I have little but strange problem, which I can't solved.

    Java Code:
    public void mouseClicked(MouseEvent e) {
                       
           JTabbedPane pane = (JTabbedPane)e.getSource();          //line 1
           //String tabTitle = pane.getTitleAt(pane.getSelectedIndex());
           fi.jpmsgTxtPane.setText(pane.getTitleAt(pane.getSelectedIndex()));
           
           if(pane.getTitleAt(pane.getSelectedIndex()).equals("DRAW")||pane.getTitleAt(pane.getSelectedIndex()).equals("DRAG")||pane.getTitleAt(pane.getSelectedIndex()).equals("MEASURE")){
               fi.sdmFlag = pane.getSelectedIndex();
           }        
           else{
               fi.sdiFlag = pane.getSelectedIndex();
           }  // line 12
               
    
           
           
           fi.mouseGetX = e.getX();
           fi.mouseGetY = e.getY();
           
           final int clickDelay=100; //delay in msec before processing events
           if (e.getClickCount() == 1) {
               JOptionPane.showMessageDialog(rootPane, "1111111111");
               fi.clickTimer=new Timer(clickDelay, (ActionListener)e);
    //            fi.clickTimer=new Timer(clickDelay, new ActionListener(){
    //                public void actionPerformed(ActionEvent e){
                        AffineTransform invtransformer = new AffineTransform();
                        invtransformer.scale(1,-1);
                        invtransformer.translate(-fdc.getWidth()/2, -fdc.getHeight()/2);
                                                                    //do something for the single click
                        fi.pt=new Point(fi.mouseGetX,fi.mouseGetY);
                        fi.tpt= invtransformer.transform((Point2D)fi.pt, null);
                        fi.pl.add(fi.pt);
    //                }
    //            });
                fi.clickTimer.setRepeats(false); //after expiring once, stop the timer
                fi.clickTimer.start();
          }
          if (e.getClickCount() == 2) {
                JOptionPane.showMessageDialog(rootPane, "222222222");
    //            fi.clickTimer.stop(); //the single click will not be processed
                fi.dpt=new Point(fi.mouseGetX,fi.mouseGetY);
                AffineTransform invtransformer = new AffineTransform();
                invtransformer.scale(1,-1);
                invtransformer.translate(-fdc.getWidth()/2, -fdc.getHeight()/2);
                            
    
                fi.tdpt= invtransformer.transform((Point2D)fi.dpt, null);
                //JOptionPane.showMessageDialog(rootPane, fi.tdpt.getX());
                fi.p22.add(fi.dpt);
         //do something for the double click
         }     
          
           fdc.repaint();
        }

    In the above code when I double clicked it can't get through the second if condition, but if I remove or comment the lines line 1 to line 12 it works fine, the second if condition is working.

    So what's the problem?
    Please help me guys..........

    Thanks

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    What values do you see returned by the getClickCount method if you print it first thing in the method?

    if I remove or comment the lines line 1 to line 12 it works fine, the second if condition is working.
    Are you saying that removing some lines of code changes the value returned by getClickCount?

  3. #3
    Marcoita_88 is offline Member
    Join Date
    Aug 2011
    Location
    Italy
    Posts
    9
    Rep Power
    0

    Default

    I give you a suggestion that help me in this cases:
    Put a breakpoint on EACH line, and follow the program line by line. For every line look the value of the variables.
    I solved many problems in this way, due to exceptions or null variables/references.

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Are you saying that removing some lines of code changes the value returned by getClickCount?
    If so, maybe there is something exceptional going on. Run the application so you can see any runtime error messages. Are there any?

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default

    The Swing Timer started in the response to the single click is possibly bogging down the EDT just enough to prevent detecting a double click.

    To get better help sooner, post a SSCCE that clearly demonstrates your problem. And make sure you keep it as short as possible by not including anything that isn't relevant to the problem.

    db

Similar Threads

  1. Thread problem, calling method in run method
    By majk in forum Threads and Synchronization
    Replies: 4
    Last Post: 09-27-2010, 11:40 AM
  2. MouseClicked Stop Animation
    By xpngamer in forum New To Java
    Replies: 1
    Last Post: 04-14-2009, 09:38 AM
  3. Replies: 6
    Last Post: 04-05-2009, 11:28 PM
  4. Method problem
    By Jeff6461 in forum New To Java
    Replies: 1
    Last Post: 03-02-2009, 06:48 AM
  5. Replies: 29
    Last Post: 09-25-2008, 07:55 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •