setColor() gives a null error on execution
I am trying to create a circle. Everything compiles, but dies during the execution. I have a button that is supposed to add the circle graphics to the screen. The buttons and the event action listener works otherwise it wouldn't get this far.
Can anyone help?
The error message printed when it hits the setColor() function is "null".
I assume that is because it thinks g is null. I'm confused in how to new g, since it doesn't let me. Graphics is an abstract class so I don't think that was possible.
public class Circle extends JComponent
x = 0;
y = 0;
// Draw a circle that can have a transposable position
public void paint (int x, int y)
System.out.println("In Function: paint");
this.x = x;
this.y = y;
System.out.println("Set X and Y");
System.out.println("Set color"); // <--------NEVER PRINTS LINE BEFORE FAILS
g.fillOval (50 + x, 50 + x, 50 + y, 50 + y);
int x, y;
sampleField = new JLabel(myName);
cirG = new Circle();
public void setSampleFont(ActionEvent event)
System.out.println("In Function: setSampleFont");
// Check for any button click
// Random Generated variables
int myX = 0;
int myY = 0;
if ( event.getSource() instanceof JButton )
// Circle Button Clicked
&& cirButtonFlag == false )
cirButtonFlag = true;
myX = getMyRandomNum();
myY = getMyRandomNum();