• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

'Disabling' mousePressed event

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need to start a thread on a mousePressed event. But there should be no further response on subsequent mousePressed events.
How do I do this? Can someone help me?
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to set boolean value, so that in the first press make it false inside the mouseclick event code.
For every mouse press event check the boolean. For the first time the boolean will be true and the mouseclick event will occur, inside the statements change the boolean value as false. So that for up coming mouseclick event will check for the boolean and comes out executing nothing.


declare the boolean variable (flag) globally with value true.
Hope it will satisfy your need.

 
Malli Murugan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rajan
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Malli,
Rajan's idea might look like it works, but it is not the way to perform what you want. If you use his method all the events will still be delegated which will just bog down the JVM. A cleaner approach would be to make use of the removeListener methods. They were created for just such a purpose. See the following code for an example.

Regards,
Manfred.
 
Javaoops
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Manfred !!!
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, so what happens when you click the mouse again? If you just removed the listener. Maybe I just missed something in the code, but do you have to add the listener back every time?
reply
    Bookmark Topic Watch Topic
  • New Topic