Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-21-2008, 10:43 PM
Moderator
 
Join Date: Nov 2007
Posts: 1,657
Java Tip will become famous soon enoughJava Tip will become famous soon enough
How to create animation
This Java tips creates a simple animation infrastructure using threads and
overwritten paint(Graphics g) method.

Code:
import java.applet.Applet; import java.awt.Graphics; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class AppletAnimation extends Applet implements Runnable { int frameNumber = -1; int delay = 100; Thread animatorThread; boolean frozen = false; public void init() { String str; addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (frozen) { frozen = false; start(); } else { frozen = true; stop(); } } }); } public void start() { if (!frozen) { if (animatorThread == null) { animatorThread = new Thread(this); } animatorThread.start(); } } public void stop() { animatorThread = null; } public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); long startTime = System.currentTimeMillis(); Thread currentThread = Thread.currentThread(); while (currentThread == animatorThread) { frameNumber++; repaint(); try { startTime += delay; Thread.sleep(100); } catch (InterruptedException e) { break; } } } public void paint(Graphics g) { g.drawString("Frame " + frameNumber, 0, 30); } }
__________________
Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums! (closes on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create Animation: Paint and thread Java Tip java.awt 0 06-21-2008 10:42 PM
GUI Animation serfster New To Java 2 06-11-2008 05:37 AM
Text Animation rossomandop@acm.org AWT / Swing 4 05-30-2008 05:34 AM
GridLayout with animation? tojas AWT / Swing 3 11-13-2007 12:16 AM
Animation with Animated GIF JavaBean Java 2D 1 06-07-2007 07:11 PM


All times are GMT +3. The time now is 07:44 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org