-
Method in a method?
Is it possible to have a method in a method? I have this method that draws stuff and is automatically called when the applet runs, I can't call it because I cant pass parameters to it or call it as void without getting an error. So I want to have it in a method that will be called which will then run the draw method inside it. Is this possible?
-
You cannot declare a method inside another method, no. Why can you not pass the parameters to it? What type of parameters does it accept, and what are you passing to it? Do you get any specific error messages? (If so, paste them here.)
-
Well the lines of code that I want to call at certain times look like this:
Code:
public void paint( Graphics g ) {
g.setColor( Color.green );
for ( int i = 0; i < 10; ++i ) {
g.drawLine( width, height, i * width / 10 , 0 );
}
}
And this automaticly runs and I want to call it on cue so I could have different drawings. Any ideas?
-
I'm not sure why you'd need to call that automatically to have different drawings. You can simple use an if statement in the paint() function, like so:
Code:
public void paint(Graphics g) {
if (someVariable == true) {
// code to draw a red box
} else {
// code to draw a green box
}
}
Now that's a very simple code, but you can take it as far as you want. There's really no need to invoke the method manually--unless you want to start doing offscreen painting.
-
Omg, I dunno why I didn't think of that earlier, thanks!. You have been so much help!