Get the latest Education e-news
 

Go Back   Game Career Guide Forums > Programming
Forum Home Register Members List Mark Forums Read

Closed Thread
 
Thread Tools Display Modes
Old 10-28-2011, 12:54 AM   #1
julianak
Junior Member

Activity Longevity
0/20 8/20
Today Posts
0/11 ssssssss1
Default Animation in Java applets

Basic animation techniques

Many forms of animation are possible in Java. What all of them have in common is that they create some kind of motion on the screen by drawing successive frames at a relatively high speed (usually about 10-20 times per second).

We will start by creating a simple template applet for doing animations and slowly elaborate it until we arrive at a fairly complete applet.

Using a thread


To update the screen multiple times per second, you need to create a new Java thread that contains an animation loop. The animation loop is responsible for keeping track of the current frame and for requesting periodic screen updates. To implement a thread, you must either create a subclass of Thread or adhere to the Runnable interface.

A common mistake is to put the animation loop in the paint() method of an applet. Doing so will have strange side effects because it holds up the main AWT thread, which is in charge of all drawing and event handling.

As an example I have written a small template applet, called Example1Applet, that illustrates the general outline of an animation applet. Example1Applet shows how to create a thread and call the repaint() method at fixed intervals. The number of frames per second is specified by passing in an applet parameter. Here is an example of what you would put in your HTML document:

<applet code=Example1Applet.class width=200 height=200>
<param name=fps value=20>
</applet>
julianak is offline  
Old 10-31-2011, 11:45 AM   #2
Protector one
Moderator

Activity Longevity
2/20 17/20
Today Posts
1/11 ssssss692
Location: Netherlands
Default Re: Animation in Java applets

what is this i don't even
__________________
My name is Louis. Hi!
Uh oh! The princess is in another signature!
Protector one is online now  
Old 01-26-2012, 06:28 AM   #3
Jane
Junior Member

Activity Longevity
0/20 7/20
Today Posts
0/11 ssssssss1
Default Re: Animation in Java applets

Thanks for the info, I am very interested in learning how to do java animation!
Jane is offline  
Closed Thread


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


Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
All times are GMT -8. The time now is 10:30 AM.






UBM Tech