The moose likes Swing / AWT / SWT and the fly likes Move an image across a screen ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Move an image across a screen ?" Watch "Move an image across a screen ?" New topic

Move an image across a screen ?

Avin Sinanan
Ranch Hand

Joined: Nov 07, 2001
Posts: 109
Hello I am building an Application..NOT an APPLET... and I need to know how to move a Gif File from one point to another. Lets say I want to move teh gif file from point (10,10) on the JPanel to point (50, 90). The image must move in a smooth motion between those points. How do I perfrom this animation?
any one have any code?

yours respectfully<br />Avin Sinanan
Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
Hi Avin,
This type of animation is usually done by painting the image in different positions accross the screen between the two points. Generally a for loop with a Thread.sleep( x milis ) will do the trick.
Be aware however that if you don't put this painting into a background thread your application will be "frozen" to user input while the painting takes place.
I suggest you search on the Sun site for "SwingWorker" and you'll find a nice little implementation for Swing applications.
Hope that helps,

Raising Flares debut album 'Ignition' out now

Terry Doyle <br />SCPJ 1.4 , SCWCD , SCMAD(Beta)
I agree. Here's the link:
subject: Move an image across a screen ?
It's not a secret anymore!