• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simplest possible Left-Mouse-Button-Clicked event  RSS feed

 
Jonathan Bjerche
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need a very simple event that activates anytime Left-Mouse-Button is clicked.

I'm looking at the mouse-listener java class. < Everything just looks overcomplicated for this small task.

Any ideas?
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a MouseListener like you already found out; perhaps you can extend MouseAdapter to help you with implementing the methods you don't need.
Implement mouseClicked.
Check the event's button.
If it's button 1, do your dirty work.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
another option
SwingUtilities.isLeftMouseButton(MouseEvent);
inside mousePressed or mouseReleased (mouseClicked doesn't always fire).
 
Randall Twede
Ranch Hand
Posts: 4696
8
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i agree, mousepressed() or mouseReleased() is usually what you want
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!