|
-
October 12th, 1999, 01:19 AM
#1
technical help
I am using jdk 1.1.5,i have written a Timer class in an Applet.
I am passing the parameter from the html file,
I want the arrow to take the path specified as follows
arr_pathx1=170;
arr_pathy1=30;
arr_pathx2=200;
arr_pathy2=100;
I have written the following program for this
The value given from the html file for arrow path is in Pixels,but that
is not taken into account in my program.
So please tell me where i am going wrong
import java.applet.*;
import java.awt.*;
import java.net.*;
import java.io.*;
import java.lang.*;
import java.util.*;
interface verTimed
{
public void tick(verTimer t);
}
class verTimer extends Thread
{
public verTimer(verTimed t)
{
target = t;
}
public void run()
{
while(true)
{
target.tick(this);
try
{
sleep(200);
}
catch(InterruptedException e)
{
}
}
}
private verTimed target;
}
public class arrotesting extends Applet implements Runnable,verTimed
{
//all the variables are taken into consideration
String text = "hello";
verTimer timer1;
int textx=40;
int texty=50;
public void init()
{
setBackground(Color.white);
img1 =getImage(getCodeBase(),getParameter("main.gif"));
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
g.drawImage(img1,0,0,this);
if(once)
{
once = false;
if(show_text == 1)
{
if(step_number == 1)
{
//g.drawString(text,textx,texty);
}
else if(step_number == 2)
{
//g.drawString("testing",textx,texty);
}
else if(step_number == 3)
{
//g.drawString("testing",textx,texty);
}
}
}
}
public void tick(verTimer t)
{
if(count==0)
{
count =30;
}
else
{
count--;
}
if(count==30)
{
Graphics g;
g = getGraphics();
step_number++;
if(step_number==1)
{
g.drawString("fjhknjf",textx,texty);
//repaint(0,0,200,100);
}
else if(step_number==2)
{
showStatus("hello");
g.drawString("djghkghkdjdk",textx,texty);
//repaint(0,0,200,100);
}
else if(step_number==3)
{
showStatus("hello");
g.drawString("dfjdhdgkdhfguoiudfigu",textx,texty);
//repaint(0,0,200,100);
}
}
else
{
if(step_number == 1)
{
showStatus("gdfg"+curr_x+","+curr_y);
if(count>20)
{
show_arr = 1;
prev_x = curr_x;
prev_y = curr_y;
repaint(prev_x,prev_y,31,31);
drawArrow(curr_x,curr_y);
}
}
else if(step_number == 2)
{
showStatus("gdfg"+curr_x+","+curr_y);
if(count>20)
{
show_arr = 1;
prev_x = curr_x;
prev_y = curr_y;
curr_x = curr_x+arr_pathx1;
curr_y = curr_y+arr_pathy1;
repaint(prev_x,prev_y,31,31);
drawArrow(curr_x,curr_y);
}
}
else if(step_number == 3)
{
showStatus("gdfg"+curr_x+","+curr_y);
if(count>20)
{
show_arr = 1;
prev_x = curr_x;
prev_y = curr_y;
curr_x= curr_x+arr_pathx2;
curr_y= curr_y+arr_pathy2;
repaint(prev_x,prev_y,31,31);
drawArrow(curr_x,curr_y);
}
}
}
}
public void run()
{
timer1 = new verTimer((verTimed)this);
timer1.start();
show_text = 1;
}
public void start()
{
timer1 = new verTimer((verTimed)this);
timer1.start();
show_text = 1;
}
public void destroy()
{
show_text = 0;
timer1.stop();
timer1=null;
repaint();
}
void drawArrow(float x,float y)
{
if(show_arr==1)
{
int num = 8;
int xpoints[] = {(int)(x+20),(int)(x+25),(int)(x+30),(int)(x+27),(int)(x+27),(int)(x+23),(int)(x+23),(int)(x+20)};
int ypoints[] = {(int)(y+10),(int)(y+5),(int)(y+10),(int)(y+10),(int)(y+20),(int)(y+20),(int)(y+10),(int)(y+10)};
Graphics g;
g = getGraphics();
g.setColor(Color.red);
g.fillPolygon(xpoints,ypoints,num);
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|