I have been looking for a way but they all throw me an error, I would like you to help me with this. I am doing a minesweeper and I need that when I right click it I get a caution flag.
JButton boton = new JButton();
I have been looking for a way but they all throw me an error, I would like you to help me with this. I am doing a minesweeper and I need that when I right click it I get a caution flag.
JButton boton = new JButton();
You can do this by adding a
ActionListener
and checking modifiers:Left button would be
getModifiers() & 16
and the middle buttongetModifiers() & 8
.Alternatively you could use a
MouseListener
:If you use
onMousePressed
andonMouseReleased
you can display your information only while the button is pressed.Explained in another way, you only have to create the mauseclicked event of the button you need and with a conditional function obtain which mouse button is being pressed, for example:
private void ClickaMouseClicked(java.awt.event.MouseEvent evt) {