tommyboyau
Programmer
Hi Guys,
I am looking for some help creating a graphics object. At least thats what I think I want to do. Here is my scenario:
- thePainter.java - does the painting to the JPanel
- otherFile.java - does some other processing things not directly related to the applet however I would like it to generate graphics objects say a label or rectangle which can be passed to thePainter.java
Can someone give me some advise on this?
I have a method in otherFile.java which would return this object but i'm not sure how to setup a Graphics object if you get my drift. This is what I have:
public Graphics getSquare()
{
Graphics g = null;
g.create(15,15,40,40);
g.setColor(Color.green);
g.fillRect(15,15,40,40);
return g;
}
I am calling it using this in thePainter.java - paintComponent(currentGrid.getTom()); - that is within public void paintComponent(Graphics g).
I would have thought that would work ok but it keeps saying I am returning a Null Pointer exception or something when I run it?
Thanks,
Tom
I am looking for some help creating a graphics object. At least thats what I think I want to do. Here is my scenario:
- thePainter.java - does the painting to the JPanel
- otherFile.java - does some other processing things not directly related to the applet however I would like it to generate graphics objects say a label or rectangle which can be passed to thePainter.java
Can someone give me some advise on this?
I have a method in otherFile.java which would return this object but i'm not sure how to setup a Graphics object if you get my drift. This is what I have:
public Graphics getSquare()
{
Graphics g = null;
g.create(15,15,40,40);
g.setColor(Color.green);
g.fillRect(15,15,40,40);
return g;
}
I am calling it using this in thePainter.java - paintComponent(currentGrid.getTom()); - that is within public void paintComponent(Graphics g).
I would have thought that would work ok but it keeps saying I am returning a Null Pointer exception or something when I run it?
Thanks,
Tom