Code:
import java.awt.*;
import java.applet.*;
public class YoYo2 extends Applet //make the class
{
private int ind = 0;
private int x = 20;
private int y = 20;
int[] hor = { 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60};
int[] vert = { 40,90, 100, 110, 120, 130, 140, 150, 160, 170, 180};
int[] cHor = { 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50};
int[] cVert = { 40,90, 100, 110, 120, 130, 140, 150, 160, 170, 180};
private int sleep = 150;
public void start()
{
ind = 0;
}
public void paint(Graphics gr)
{
gr.setColor(Color.WHITE);
gr.drawLine(60, 40, hor[ind], vert[ind]);
gr.fillOval(cHor[ind], cVert[ind],x, y);
++ind;
if(ind == hor.length)
ind = 0;
gr.setColor(Color.BLACK);
gr.drawLine(60, 40, hor[ind], vert[ind]);
gr.fillOval(cHor[ind], cVert[ind],x, y);
try
{
Thread.sleep(sleep);
}
catch(InterruptedException e)
{
}
repaint();
}
}
Bookmarks