62,614
社区成员
发帖
与我相关
我的任务
分享
class Packet extends JPanel
{
private double s_x,s_y,e_x,e_y;
private String s_ID;
private Double move_time;
private double a,b,c;
private double receiver_sped;
private double step;
private int x,y;
public Packet(int cs_x,int cs_y,int ce_x,int ce_y,double cmove_time,double creceiver_sped,String cs_ID)
{
this.s_x=cs_x;
this.s_y=cs_y;
this.e_x=ce_x;
this.e_y=ce_y;
this.move_time=cmove_time;
this.receiver_sped=creceiver_sped;
this.s_ID=cs_ID;
//System.out.println("SX:"+s_x+" "+"SY:"+s_y+" "+"EX:"+e_x+" "+"EY:"+e_y+" "+"Mtime:"+move_time+" "+"rsped:"+receiver_sped+" "+"ID:"+s_ID);
getTarget();
//System.out.println("Packet_public_2");
// run();
//System.out.println("Packet_public_3");
}
public void getTarget() {
double x1 = this.s_x;
double y1 = this.s_y;
double x3 = e_x;
double y3 = e_y-this.move_time*this.receiver_sped;
a = (float) (y3 - y1) / (float) (x3 - x1);
b = (float) (y3 * (x3 - x1) - x3 * (y3 - y1)) / (float) (x3 - x1);
step = (x3 - x1)/(this.move_time);
//System.out.println("ID:"+this.s_ID);
//System.out.println("x1:"+x1+" "+"y1:"+y1+" "+"x3:"+x3+" "+"y3:"+y3+" "+"a:"+a+" "+"b:"+b+" "+"step:"+step);
}
public void paint(Graphics g)
{
super.paint(g);
//System.out.println("run_x:"+x);
x += 50;
if(x>this.e_x)
x=(int)this.s_x;
y = (int) (a * x + b);
if (y > this.e_y) {
//_z.isLive = false;
}
System.out.println("ID:"+this.s_ID);
//g.setColor(Color.BLUE);
//g.fillRect(x, y, 20, 20);
g.setColor(Color.RED);
g.drawString(this.s_ID, x, y+20);
//repaint();
}
}
if (Double.parseDouble(timeStr(Start)) == open.STIME[i]){
Packet packet = new Packet(senderX, senderY, receiverX, receiverY,
open.move_time[i], (double) delay1[receiverID] / 1000,
open.sender[i][5]);
add(packet);
packet.setOpaque(false);
packet.setBounds(0, 0, 800, 1000);
}
这个是之前的初始化条件语句