Applet Animations
Applet Animations
package Applet;
import java.awt.*;
import java.applet.*;
// enter message
Thread t = null;
// initialize here.
int state;
boolean stopFlag;
setBackground(Color.cyan);
setForeground(Color.red);
t = new Thread(this);
stopFlag = false;
t.start();
}
// Entry point which runs the text.
char ch;
for (;;) {
try {
repaint();
Thread.sleep(250);
ch = msg.charAt(0);
msg += ch;
if (stopFlag)
break;
} catch (InterruptedException e) {
System.out.println(e);
stopFlag = true;
t = null;
}
Applet program to show animation of bouncing ball
package Applet;
import java.applet.*;
import java.awt.*;
int dx = 11, dy = 7;
// create thread.
Thread t;
boolean stopFlag;
t = new Thread(this);
stopFlag = false;
t.start();
g.fillOval(x - r, y - r, r * 2, r * 2);
while (true) {
if (stopFlag)
break;
x += dx;
y += dy;
try {
Thread.sleep(100);
} catch (Exception e) {
System.out.println(e);
};
repaint();
stopFlag = true;
t = null;
}
}