I am a beginner at java so am attempting to create a minesweeper game. I have a grid full of JButtons that when clicked reveal numbers or mines.
I want to add "flags" so when I right click on any button it changes colour - showing it has been flagged and is 'locked' so it cannot be clicked on unless right clicked.
Here are my buttons
public void buttons()
{
// Creating the grid with buttons
grid.setLayout(new GridLayout(20,20));
// Button grid
for (int x = 0; x < buttons.length; x++)
{
for (int y = 0; y < buttons.length; y++)
{
buttons[x][y] = new JButton();
buttons[x][y].addActionListener(this);
grid.add(buttons[x][y]);
}
}
I attempted to create this right click functionality but I am currently stuck and would like some help.
public void flag()
{
buttons.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
JButton rightClick = new JButton("Right Click");
rightClick.addActionListener(this);
}
});
}