Is there any short way to draw the same size rectangles?

We started to learn about animation in my class....Yeahh...how exciting!.

Our homework is to draw something and make it move (animate). I'm basically done but my Applet codes are reallyyyyy long. I wonder if there's an easy way of coding this. Does every object needs to have different codes. Example below: I'm making a 'broken white lines' for the street. The rectangles are all the same size, the only different is the position of the 'x'. Is there any short way of doing it?

g.setColor(Color.white);

g.fillRect(0,520,25,5);

g.fillRect(50,520,25,5);

g.fillRect(100,520,25,5);

g.fillRect(150,520,25,5);

g.fillRect(200,520,25,5);

g.fillRect(250,520,25,5);

g.fillRect(300,520,25,5);

g.fillRect(350,520,25,5);

g.fillRect(400,520,25,5);

g.fillRect(450,520,25,5);

g.fillRect(500,520,25,5);

g.fillRect(550,520,25,5);

[910 byte] By [aivon1sta] at [2007-11-27 10:52:17]
# 1

Hint: for loop

BigDaddyLoveHandlesa at 2007-7-29 11:36:36 > top of Java-index,Java Essentials,Java Programming...
# 2

got it! Thank you!

aivon1sta at 2007-7-29 11:36:36 > top of Java-index,Java Essentials,Java Programming...