I'm working on a piece of code which randomly puts circles across the screens for my game(simply put). I have no error in the code but I've got into a problem where it wants to write more paint code but I want to type more, here is the code. I'm Using JFrame for this
public class Game extends JPanel{
public static final long serialVersionUID = 2L;
public static Random random;
public void paintComponent(Graphics g){
super.paintComponent(g);
this.setBackground(Color.BLACK);
Dimension ScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
int width = (int) ScreenSize.getWidth();
int height = (int) ScreenSize.getHeight();
for(int i=1; i<12; i++){
int rw = random.nextInt(width);
int rh = random.nextInt(height);
int radius = random.nextInt(50);
g.setColor(Color.gray);
g.fillOval(rw, rh, radius+50, radius+50);
}
` Error Code comes out like this
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Game.paintComponent(Game.java:18)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
Simply put, what have I done wrong and How may i fix it?