Results 1 to 4 of 4
- 09-28-2011, 07:53 AM #1
Member
- Join Date
- May 2011
- Posts
- 21
- Rep Power
- 0
Trouble with recursion if statement.
Basically I'm using a Jpanel set up. The aim is that there are 7 levels of recursion. Everytime I press a button to increase or decrease the recursion the pattern should change to the corresponding level of recursion. So for example level 1 is one square, level 2 is 4 squares around that square and level 3 is 4 squares around those 4 squares...
Basically I won't go into detail but the "level" is passed into the class as an int. The starting level of recursion is 1.
How would I create an if statement to let the method know only to call itself again when the method has been changed up or down?
Java Code:private void drawPattern(Graphics g, int level, double leftX, double topY, double size) { if (level ?){ drawPattern(g, level , leftX, topY,size/2);
- 09-28-2011, 09:15 AM #2
Senior Member
- Join Date
- Nov 2010
- Posts
- 210
- Rep Power
- 10
Re: Trouble with recursion if statement.
I'm guessing you already have an instance variable called level. In that case, couldn't you do something like:
Java Code:if (level != this.level) { ... }
- 09-28-2011, 10:21 AM #3
Member
- Join Date
- May 2011
- Posts
- 21
- Rep Power
- 0
Re: Trouble with recursion if statement.
Nope, the code just never executes.
- 09-28-2011, 03:41 PM #4
Similar Threads
-
new to java, trouble with if statement
By Globular in forum New To JavaReplies: 8Last Post: 05-25-2011, 07:03 PM -
Having trouble tracing this recursion method. Can't find the problem.
By TheNadz in forum New To JavaReplies: 3Last Post: 04-12-2011, 07:44 AM -
recursion and tail-recursion differences
By OptimusPrime in forum New To JavaReplies: 2Last Post: 12-28-2009, 07:26 PM -
Help with Recursion and return statement
By nicolek808 in forum New To JavaReplies: 3Last Post: 09-10-2009, 11:02 AM -
Statement or Prepared Statement ?
By paty in forum JDBCReplies: 3Last Post: 08-01-2007, 05:45 PM
Bookmarks