Here is my main program to draw a bug when rolling a dice
I need to set a timer for it?
Here I added somethings from the examples but im not sure what to put in
for (Shape shape : shapes) {
shape.move();
shape.decreaseDelay();
repaint();
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Timer;
public class Yahtzee extends JFrame implements ActionListener {
Die[] d; // array to hold the 5 dice
FourOfAKind[] f;
JPanel dicePanel; // panel to hold the dice
JPanel bugPanel;
Timer timer = new Timer();
public static void main(String[] args)
{
Yahtzee y = new Yahtzee();
}
public Yahtzee()
{
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout());
setLayout(new BorderLayout());
timer = new Timer(30, new ActionListener() {
public void actionPerformed(ActionEvent e) {
for (Shape shape : shapes) {
shape.move();
shape.decreaseDelay();
repaint();
}
}
});
JButton start = new JButton("Start");
start.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
timer.start();
}
});
JPanel panel = new JPanel();
panel.add(start);
dicePanel = new JPanel();
dicePanel.setLayout(new GridLayout(5, 1));
dicePanel.setLayout(new FlowLayout());
dicePanel.setSize(new Dimension(50, 50));
add(dicePanel, BorderLayout.CENTER);
d = new Die[1];
for (int i = 0; i < 1; i++) {
d[i] = new Die(this);
dicePanel.add(d[i]);
}
bugPanel = new JPanel();
bugPanel.setLayout(new GridLayout(5, 5));
bugPanel.setLayout(new FlowLayout());
bugPanel.setSize(new Dimension(50, 50));
add(bugPanel, BorderLayout.SOUTH);
f = new FourOfAKind[1];
for (int w = 0; w < 1; w++) {
f[w] = new FourOfAKind(this);
bugPanel.add(f[w]);
}
setSize(new Dimension(715, 705));
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
repaint();
timer.start(); // start timer
}
public void setChoice(int choice) {
f[0].setChoice(choice);
}
public void drawBug() {
f[0].setChoice(d[0].getChoice());
f[0].drawBug();
}
}