distance = ( Math.abs( x - 160 ) + Math.abs( y - 160 ) ) / 30;
JOptionPane.showMessageDialog(null,"The ant traveled around the block " + distance + " times.");
} // paint method } // RandomWalk ___________________________________________________________________________ any help would be greatly appericated.
<b><i>To err is human but to really mess up the things you need a computer </b></i>
Joined: Apr 20, 2004
Your program is actually drawing more than the 4 dots its just that they are on top each other as you are repeatedly drawing at the same locations. I think what you are trying to do in your case statement is move x and y positions but are instead just using the same offsets.
Instead of g.fillOval( x-3, y+30, side, side ); try g.fillOval( x-=3, y+=30, side, side );
-= & += will decrement and increment the values accordingly.
Hope this helps.
Joined: Dec 06, 2001
I would suggest a slightly different modification to your code. Instead of do
Personally, I think this is clearer than Richard's suggestion in that you are not trying to do so many things in a single line of code.