• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with For Loop?

 
Thomas Crew
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to have each shape that's in the array move around the canvas randomly and independently. When the shape (array[i]) goes out of the canvas, it should be reset in another random location to continue moving once again. Can anyone tell me what's wrong with this code?

The "Driver" class draws the shapes from the class Star on to the canvas.






 
fred rosenberger
lowercase baba
Bartender
Posts: 12143
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is a lot of code to expect someone to go through, and not much info on where to look. Can you simply/reduce the amount of code you post but still demonstrate the issue? Preferably one we can compile and run as-is.

Generally speaking, when stuff isn't working how I think it should, I start sticking in System.out.println() statement. Put them in at the top and bottom of each method telling me that I am entering/leaving. Put them in each time you change a variable. Put them in at the top of a loop. Put them in before each IF statement, or in each block of the If/else if/else block.

eventually, you can narrow down where the problem is, and figure out why something isn't changing that should, or is changing that shouldn't.
 
Rajdeep Biswas
Ranch Hand
Posts: 221
1
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever theres trouble, debug it.
If you a beginner, you may take my recommendation
If you are on console, go for System.out.println statements as Fred insisted, and if you're with an IDE, add debug points to important locations and run the program in debug mode, and see that the variables are having what values! And you will be on track again!
And yes, this big code is very hard to read in a short span, so its recommended for OP to show some research effort and narrow down the question to specific issues!
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic