I need the program to draw an ellipse when I press the Start button. That would be the basis for after a little game like the pacman or the little vibrator, but I got to this step and I got stuck, I really do not know what to do. The classes make me dizzy and I do not know how to link them together, create the variable started so that when you press the button it is drawn but I do not know what happens, since it does not draw the ellipse at the moment of the apprehension and apparently the variable started already starts alone. if you do not touch the button. I am new programming, it is enough of java syntax but the logic is failing me a lot
public class Game extends JFrame {
public Game() {
setBounds(300,300,600,600);
setResizable(false);
setTitle("Juego de Pelota Beta");
setLayout(new BorderLayout());
LaminaGame lamina=new LaminaGame();
add(lamina, BorderLayout.CENTER);
setVisible(true);
}
}
// Creo la clase encargada de la lamina sobre el JFrame y con los metodos para dibujar a la vibora.
class LaminaGame extends JPanel {
public LaminaGame() {
Container e=this;
e.setBackground(Color.black);
setLayout(new BorderLayout());
add(new ClaseBotones(),BorderLayout.SOUTH);
if(ClaseBotones.iniciado=true) {
Dibujadora dibujo=new Dibujadora();
}else {
}
}
private class Dibujadora extends JPanel{
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2=(Graphics2D)g;
g2.setColor(Color.GREEN);
g2.draw(new Ellipse2D.Double(200,200,200,200));
}
}
}
class ClaseBotones extends JPanel{
public ClaseBotones() {
setBackground(Color.BLACK);
JButton boton1=new JButton("Iniciar");
boton1.setBackground(Color.GREEN);
add(boton1);
JButton boton2=new JButton("Salir");
add(boton2);
boton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
boton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
iniciado=true;
}
});
}
static boolean iniciado=false;
}