File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Graphic g problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Graphic g problem" Watch "Graphic g problem" New topic
Author

Graphic g problem

Adam Polak
Greenhorn

Joined: Oct 28, 2002
Posts: 23
I've got a bit of problem with the following script.
In the lines 68 & 121 t/m 125 I get an error with the g variable as it says its undefined.
Could someone please help me out with this?


[ January 04, 2003: Message edited by: Marilyn de Queiroz ]
Adam Polak
Greenhorn

Joined: Oct 28, 2002
Posts: 23
As there are no line numers here..to be precise its the part with:
"achtergrond1 = new Achtergrond(g);" & " b1.toon(g);
b2.toon(g);
b3.toon(g);
b4.toon(g);
b5.toon(g);"
the first part has a // in front of it but that is something I added after I had to problem to sort something out.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12
In the lines 68 & 121 t/m 125 I get an error with the g variable as it says its undefined.
Could someone please help me out with this?



Are you trying to override the paint() method of the Component class? this one?

void paint(Graphics g)

Notice that the signature of your paint method is different.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Adam Polak
Greenhorn

Joined: Oct 28, 2002
Posts: 23
I dont think I understand
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
He is trying to say that you need to change void paint() to void paint(Graphics g). This will override the paint() method of the Component class and allow your stuff to paint itself correctly. Since you have just void paint(), this is a different function and won't be called by the system when it decides your applet needs to be painted. The simple change above will fix that, as well as your "undeclared identifier" problem.
HTH
Layne


Java API Documentation
The Java Tutorial
Adam Polak
Greenhorn

Joined: Oct 28, 2002
Posts: 23
Thank you I got rid of the problem in line 121-125 but I still get a problem in line 68, the same problem is says "undefined variable: g achtergron1 = new Achtergrond(g);
the code looks like this now:
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
The compiler is telling you that the variable g has not been declared in the function from which you are trying to use it. In the init() function of an applet, there is no Graphic object for you to draw to; it hasn't been initialized yet. You probably should probably change the constructor for Achtergrond to accept no parameters. Then call its various methods from the paint() method that was discussed previously.
I have a question for you. Is there a reason the Lucht(), Grond(), Wolk() Zon() methods are in their own class? It would probably be easiest if these were simply inside the SpeelBalon class instead. You would still call them from paint(), either way.
HTH
Layne
p.s. Instead of posting the whole program, you should only post the few lines where the error occurs, perhaps the function with the error, but usually not much more than that.
Adam Polak
Greenhorn

Joined: Oct 28, 2002
Posts: 23
Thanks for the help! I got it to work good now.
The reason they need a seperate class is because it's an asignment I need to do and it's written this way.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Graphic g problem