I am trying to set a timer class to control when the ball chooses a new color. I need to make the ball change colors at a set time and not just continuously set different colors. This is my ball class and the whole program is run through a start class.
public void go() {
if (dx >= 0) {
dx = 20;
}
}
public void update(Start sp) {
if (x + dx > sp.getWidth() - radius * 2) {
x = sp.getWidth() - radius * 2;
dx = -dx;
}
else if (x + dx < 0) {
dx = -dx;
}
else {
x += dx;
}
}
public void paint(Graphics g) {
Random set = new Random();
int num1;
num1 = set.nextInt(4);
if (num1 == 0) {
g.setColor(Color.blue);
g.fillOval(x, y, radius * 2, radius * 2);
}
if (num1 == 1) {
g.setColor(Color.green);
g.fillOval(x, y, radius * 2, radius * 2);
}
if (num1 == 2) {
g.setColor(Color.white);
g.fillOval(x, y, radius * 2, radius * 2);
}
if (num1 == 3) {
g.setColor(Color.magenta);
g.fillOval(x, y, radius * 2, radius * 2);
}
}