• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to make rectangle move in a random direction  RSS feed

 
Angel Brown
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am trying to learn Java swing and I wanted to draw a rectangle that will move in a random direction but when it collides with a wall it should change a direction of its movement.
So I have this code:

but it stops after the first time when it is done and it moves so quickly that I cannot see the movement.
I have another code it works perfectly fine I just don't understand why the first code doesn't work when I used the same logic but tried to do it more complicated
here is my second code

Can someone help thanks in advance
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!