I moved setVisible() to after everything as you suggested but still get the same errors as most recently stated above. I also see your points about the for loop so I commented those out for now and made some changes to the Draw program:
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class Draw extends JPanel {
int shape;
public Draw() {
shape = 4;
}
public Draw(Color backColor) {
setBackground(backColor);
}
//variable to hold the shape
//int shape;
private static final Random gen = new Random();
public void paintComponent(Graphics g) {
super.paintComponent(g);
//g.setColor(Color.BLACK);
//g.fillOval(20, 50, 100, 50);
//g.setColor(Color.BLUE);
//g.fillOval(150, 25, 100, 100);
//g.setColor(Color.RED);
//g.fillRect(275, 25, 100, 100);
//for(int i = 0; i < 4; i++) {
shape = chooseShape(); //added this
switch (shape) {
case '1':
g.setColor(Color.BLACK);
g.fillOval(20, 50, 100, 50);
break;
case '2':
g.setColor(Color.BLUE);
g.fillOval(150, 25, 100, 100);
break;
case '3':
g.setColor(Color.RED);
g.fillRect(275, 25, 100, 100);
break;
}
//}
}
public static int chooseShape() {
int theShape = 1 + gen.nextInt(3);
return theShape;
}
}