I am doing the game for java and when starting the machine will give a random click drying on 4 buttons and then the user has to press the same as the machine, but I do not know how to make the machine push the button
package gênius;
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
public class tela extends JFrame {
//nome do jogador e pontos
int pontos = 0 ;
String usuario = "";
//varieaveis de jogadas
String jjogador = "";
String maquina ="";
// janela de exibição
public void janela(){
JFrame ftela = new JFrame();
ftela.setTitle("Gênius");
ftela.setSize(400, 600);
ftela.setBackground(Color.white);
ftela.setLocationRelativeTo(null);
ftela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ftela.setVisible(true);
//boões de ção
JButton b1 = new JButton("");
b1.setBounds(100, 220, 80, 80);
b1.setVisible(true);
b1.setBackground(Color.BLUE);
JButton b2 = new JButton("");
b2.setBounds(200, 220, 80, 80);
b2.setVisible(true);
b2.setBackground(Color.red);
JButton b3 = new JButton("");
b3.setBounds(100, 320, 80, 80);
b3.setVisible(true);
b3.setBackground(Color.GREEN);
JButton b4 = new JButton("");
b4.setBounds(200, 320, 80, 80);
b4.setVisible(true);
b4.setBackground(Color.YELLOW);
JButton b5 = new JButton("vermalho");
b5.setBounds(200, 420, 80, 80);
b5.setVisible(true);
b5.getColorModel();
b5.setBackground(Color.WHITE);
JPanel p1 = new JPanel();
ftela.add(b1);
ftela.add(b2);
ftela.add(b3);
ftela.add(b4);
ftela.add(b5);
//ações dos botôes
b1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
play("b1");
jjogador += " "+0;
}
});
b2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
play("b2");
jjogador += " "+1;
}
});
b3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
play("b3");
jjogador += " "+2;
}
});
b4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
play("b4");
jjogador += " "+3;
}
});
b5.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, jjogador);
}
});
}
// coloando som no botão
public void play(String audio){
URL url = getClass().getResource(audio+".wav");
AudioClip audioc = Applet.newAudioClip(url);
audioc.play();
}
public void jlabe (){
JLabel mPontos = new JLabel("pontos ");
mPontos.setText("pontos :"+pontos);
mPontos.setHorizontalAlignment(SwingConstants.CENTER);
}
}