Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

'Disabling' mousePressed event  RSS feed

 
Malli Murugan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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?
 
Javaoops
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Rajan
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Manfred !!!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!