Results 1 to 5 of 5
Thread: Method in a method?
- 07-31-2010, 04:09 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 74
- Rep Power
- 0
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?
- 07-31-2010, 04:32 AM #2
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.)
- 07-31-2010, 04:38 AM #3
Member
- Join Date
- Jul 2010
- Posts
- 74
- Rep Power
- 0
Well the lines of code that I want to call at certain times look like this:
And this automaticly runs and I want to call it on cue so I could have different drawings. Any ideas?Java 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 ); } }
- 07-31-2010, 04:44 AM #4
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:
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.Java Code:public void paint(Graphics g) { if (someVariable == true) { // code to draw a red box } else { // code to draw a green box } }
- 07-31-2010, 04:47 AM #5
Member
- Join Date
- Jul 2010
- Posts
- 74
- Rep Power
- 0
Similar Threads
-
Turning Recursion Method into Iterative method
By mattakuevan in forum New To JavaReplies: 9Last Post: 06-15-2010, 06:46 AM -
method not abstract, does not override actionperformed method.
By Theman in forum New To JavaReplies: 2Last Post: 03-26-2010, 05:12 PM -
ArrayLists compareTo method, equals method
By random0munky in forum New To JavaReplies: 2Last Post: 10-26-2009, 07:20 PM -
Calling a method in a different class from within a method problem
By CirKuT in forum New To JavaReplies: 29Last Post: 09-25-2008, 07:55 PM -
cannot call private method from static method
By jon80 in forum New To JavaReplies: 3Last Post: 05-07-2008, 08:37 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks