|
||||||||||||||
. . . . . |
| Intro |
Begin |
if/else |
Loops |
Arrays |
Graphics |
Animation |
Mouse |
Game |
Real |
Methods |
Class |
Class 2 |
Applet |
MouseClick |
Thread |
Button |
Simple Java Animation Using Threads
import java.awt.*;
import java.applet.*;
public class TestAnim1 extends Applet implements Runnable {
//Declare a Thread object
Thread count;
int x ;
int y;
// initialise applet
public void init()
{
x = 0;
y = 20;
setBackground(Color.yellow);
// init thread
count = new Thread(this);
//start the thread
count.start();
}
//Thread code , overrides run method of Runnable
public void run()
{
while(true)
{
try
{
// delay
count.sleep(100);
x++;
// call paint method
repaint();
}
catch(Exception e) {} //do nothing
}
}
// paint method
public void paint(Graphics g){
g.setColor(Color.green);
g.fillOval(x,y, 30,30);
}
}
Flash Tutorials in Video Format -
Watch them now at LearnFlash.com |
|
||||||||||||
|
. | Home | Flash MX | Actionscript 2.0 | Flash 3D | Flash 8 | Flash Database | Flash Mobile | Flash CS3 | Java For Kids | Video Course | General Video | Photoshop | Web Design | Digital Photography | Games | free backgrounds | Resume | Streaming Video | Students Work | Links | Contact me | sitemap | reviews | . . |
||||||||||||||