graphics null pointer exception
Hello,
Iam trying to make a program that displays 2 eyes, and according to the mouse movement to look up, down, left, or right
i am first drawing the eyes, here is my code
Code:
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
public class EyeGUI
{
private JFrame frame;
private JPanel eyePanel;
public EyeGUI ()
{
frame = new JFrame("The eyes have it");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(new Dimension(280, 200));
eyePanel = new JPanel ();
eyePanel.setBackground(Color.GRAY);
Graphics g = eyePanel.getGraphics();
g.setColor(Color.BLACK);
g.drawOval(40, 50, 100, 100);
g.drawOval(140, 50, 100 ,100);
frame.setVisible(true);
}
public static void main (String[] args)
{
new EyeGUI ();
}
}
the thing im having is it is highlighting on the first g. statement, fromg.setColor(..) i removed it and then it highlighted over g.drawOval(...) with a null pointer exception
what could be my problem, did i miss to call a method i should have or what?
Thanks in advance