• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Graphic g problem

 
Adam Polak
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9061
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Adam Polak
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont think I understand
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Adam Polak
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic