This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Painting shells Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Painting shells" Watch "Painting shells" New topic
Author

Painting shells

eric elysia
Ranch Hand

Joined: Mar 06, 2005
Posts: 70
I am writing a program to paint shells, for example:

149
238
567

I have written a method, but the method is not giving me the results I expect.

The approach I am using is:

rowNum = 1
As long as row is less than the size of the square side (for each row in column 1)

As long as rowNum is greater than colNum
Paint horizontally, moving from left to right
When rowNum = colNum, paint that square, then exit loop

As long as rowNum is greater than 1
Paint vertically moving up
When rowNum = 1, paint that square, then exit loop



I am getting an infinite loop, but I am not sure what condition(s) are causing the infinite loop.

[ February 10, 2007: Message edited by: eric elysia ]
[ February 10, 2007: Message edited by: eric elysia ]
eric elysia
Ranch Hand

Joined: Mar 06, 2005
Posts: 70
OK, I got my loop figured out. Now I need to be able to change the color for each shell. I know where I need to change the color, but I am not sure how to compare the color.

I do know how to set the color: graphics.setColor(Color.red);

I thought about using an if statement like this:


Here is my working paintShells method:

[ February 11, 2007: Message edited by: eric elysia ]
 
 
subject: Painting shells