these are four buttons, i wanna just select one or two button! how do i do that?
public class Game {
private JButton button1,button2,button3,button4;
public Game(){
buttonMethod();
private void buttonMethod() {
JButton button1 = new JButton("?");
button1.setFont(new Font("Tahoma",Font.BOLD,20));
button1.setBackground(Color.yellow);
panel2.add(button1);
JButton button2 = new JButton("?");
button2.setFont(new Font("Tahoma",Font.BOLD,20));
button2.setBackground(Color.yellow);
button2.addActionListener(e->{
button2.setText("2");
});
panel2.add(button2);
JButton button3 = new JButton("?");
button3.setFont(new Font("Tahoma",Font.BOLD,20));
button3.setBackground(Color.yellow);
button3.addActionListener(e->{
button3.setText("3");
});
panel2.add(button3);
JButton button4 = new JButton("?");
button4.setFont(new Font("Tahoma",Font.BOLD,20));
button4.setBackground(Color.yellow);
button4.addActionListener(e->{
button4.setText("4");
});
panel2.add(button4);
}
}
}