so I have class Board that extends JApplet and in it's constructor I make a JPanel that I'll later draw boxes on, but when I try to do getGraphics it returns null :/
JPanel panel;
public Board(int x, int y, int wolfNumber, int hareNumber){
    this.x=x;
    this.y=y;
    wolvesCoords = new int[wolfNumber][2];
    haresCoords = new int[hareNumber][2];
    panel = new JPanel();
    panel.setVisible(true);
    add(panel);
}
public synchronized void write(int xx, int yy, Color c){
    int width=panel.getWidth()/x;
    int height=panel.getHeight()/y;
    Graphics g = panel.getGraphics();
    System.out.println(g);
    g.setColor(c);
    g.drawRect(xx*width, yy*height, width, height);
    g.fillRect(xx*width, yy*height, width, height);
}
public void paint(Graphics g)
{
        super.paint(g);
}
It gives nullpointerexception at line g.setColor(c) as g is null.