Panelに長方形を表示する簡単なプログラムを作りたいのですが
以下のようにすると
"Exception in thread "main" java.lang.NullPointerException"
と出てしまいます。なぜでしょうか?

public class zukei {
public static void main(String[] args) {
JFrame frame = new JFrame();
JPanel panel = new JPanel();

frame.add(panel);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { System.exit(0)
; }
});

Graphics g = panel.getGraphics();

panel.getGraphics();
panel.setBackground(Color.red);
g.setColor(Color.blue);
g.fillRect(0,0,10,10);
frame.setVisible(true);
}

}