Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Problem with For Loop?  RSS feed

 
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.






 
lowercase baba
Posts: 12628
50
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.
 
Ranch Hand
Posts: 231
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!