'How to detect right and left click for multiple JButtons?
I am trying to make a MineSweeper game, so far I have successfully implemented a recursive tile reveal every time I click a cell. However, that is only using an ActionListener. If I wanted to be able to detect both the right and left click for each cell what do I do?
I am confused as to whether I need an ActionListener and a MouseListener for every button.
Here is my current code with an action listener:
public void actionPerformed(ActionEvent e){
int row = 0;
int col = 0;
outer:
for(row = 0; row < height; row++){
for(col = 0; col < width; col++){
if(e.getSource() == grid[row][col].getButton()){
recursiveReveal(row, col);
break outer;
}
}
}
}
But what do I do to add a mouse listener for the left and right buttons for every JButton / cell?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
