I have an applet that's only purpose is to create a box and each time it's painted it changes color. Right now it is not changing color at all, it simply creates a random background color to start and sticks with it whenever painted but I need it to change. Any help on what I'm doing wrong would be appreciated.
import java.applet.*;
import java.awt.*;
import java.util.*;
public class AppletSubClass2 extends Applet {
public void init() {
System.err.println("Hello from AnAppletSubClass.init");
setBackground(color);
}
public void paint(Graphics g) {
System.err.println("Hello from .paint!This time the applet will change colors when painted");
setBackground(new Color(randomNum1, randomNum2, randomNum3));
}
Random rand = new Random();
int randomNum1 = rand.nextInt(251);
int randomNum2 = rand.nextInt(251);
int randomNum3 = rand.nextInt(251);
Color color = new Color(randomNum1, randomNum2, randomNum3);
}