rendered paste bodyimport java.awt.*;
import java.awt.event.*;
import java.util.*;
public class TestAnim extends Panel {
Timer t;
int tick = 0;
private class RepaintTimerTask extends TimerTask
{
TestAnim parent;
RepaintTimerTask(TestAnim parent)
{
this.parent = parent;
}
public void run()
{
parent.tick++;
parent.repaint();
}
}
public TestAnim(String fn) {
t = new Timer();
t.schedule(new RepaintTimerTask(this), 500, 10);
}
public void paint(Graphics g)
{
double theta;
g.setColor(Color.black);
for(int i=0;i<60;i++)
{
theta = ((i * 6) * 3.1415/180);
g.drawLine( (int)(125 + 60*Math.sin(theta)),
(int)(125 + 60*Math.cos(theta)),
(int)(125 + 70*Math.sin(theta)),
(int)(125 + 70*Math.cos(theta)) );
}
g.setColor(Color.blue);
tick = tick % 60;
theta = -((tick * 6) * 3.1415/180);
g.drawLine( 125, 125,
(int)(125 + 50*Math.sin(theta)),
(int)(125 + 50*Math.cos(theta)) );
}
public static void main(String args[]) {
Frame f = new Frame("Hello");
TestAnim window = new TestAnim("");
f.add(window);
f.setTitle("Test");
f.setSize(250, 250);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
f.setVisible(true);
}
}