Forum Stats

  • 3,872,508 Users
  • 2,266,437 Discussions
  • 7,911,234 Comments

Discussions

Recognizing both mouse buttons clicked

843789
843789 Member Posts: 46,655 Green Ribbon
hey everyone!
thats my first post here..

as a student, i'm making a JAVA-based project for my final exams this year.
my project is a minesweeper game, yep, just like microsoft's one, only JAVA-based.

i want my mouselistener to recognize when i click BOTH left button and right button on a JButton, and when releasing at least one of them do some commands that i will program by myself already..
the only thing is i don't have a clue how to make my mouselistener recognize that.. any help please?

thanks!!

Comments

  • 843789
    843789 Member Posts: 46,655 Green Ribbon
    In mouseReleased(MouseEvent) you can check the extended modifiers using getModifiersEx() to see if the opposite button (the one not being released) is held down. For example, if the BUTTON1 is released check for BUTTON2_DOWN_MASK in the extended modifiers. If this is the case then you know that both buttons were down and the user just released BUTTON1. Check for BUTTON1_DOWN_MASK if the button is BUTTON2 and you know that both buttons were down and the user just released BUTTON2.
This discussion has been closed.