this link is what i want it to do:
http://kucourses.com/ec/courses/2472...testyoyos.html
this is the code i have
import java.awt.;
import java.applet.;
public class YoYo 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};
private int sleep = 100;
public void start()
{
ind = 0;
}
public void paint(Graphics gr)
{
boolean backwards = false;
while(true)
{
if (ind==hor.length) backwards = true;
if (ind==0) backwards = false;
if (backwards) --ind ;
else ++ind;
gr.setColor(getBackground());
gr.drawLine(60, 40, hor[ind], vert[ind]);
gr.fillOval(cHor[ind], vert[ind],x, y);
gr.setColor(Color.BLACK);
gr.drawLine(60, 40, hor[ind], vert[ind]);
gr.setColor(Color.GREEN);
gr.fillOval(cHor[ind], vert[ind],x, y);
try
{
Thread.sleep(sleep);
}
catch(InterruptedException e)
{
}
repaint();
}
}
}
Bookmarks