以下程序为多线程的java小程序实现,其功能是两个字符串在某一行来回滚动,请填空:(一共五题)
import java.awt.*;
import java.applet.Applet;
public class moveChar ① // java小程序实现Runnable接口
{ String[] ch={"welcome","beijing"};
int maxY,minY; //Y坐标范围
int index, step;
int y[]=new int[2];
Boolean ahead[]=new Boolean[2];
public void init()
{ maxY=800; minY=200;
ahead[0]=true; ahead[1]=true;
y[0]=400; y[1]=700;
step=10;
}
public void start(){
Thread t= ;② // 创建多线程程序
; ③ //启动线程
}
public { ④ //线程体方法
while(true){
try{Thread.sleep(1000); }
catch(Exception e){System.out.println(e.toString());}
if(ahead[0]) y[0]=y[0]+step; else y[0]=y[0]-step;
if(y[0]>maxY) ahead[0]= false;
if(y[0] <minY) ahead[0]= true;
if(ahead[1]) y[1]=y[1]+step; else y[1]=y[1]-step;
if(y[1]>maxY) ahead[1]= false;
if(y[1] <minY) ahead[1]= true;
;⑤ //重绘APPLET,调用paint方法
}
}
public void paint(Graphics g)
{ g.setColor(Color.red);
g.drawString(ch[0],y[0],50);
g.drawString(ch[1],y[1],50);
}
}
import java.awt.*;
import java.applet.Applet;
public class moveChar ① // java小程序实现Runnable接口
{ String[] ch={"welcome","beijing"};
int maxY,minY; //Y坐标范围
int index, step;
int y[]=new int[2];
Boolean ahead[]=new Boolean[2];
public void init()
{ maxY=800; minY=200;
ahead[0]=true; ahead[1]=true;
y[0]=400; y[1]=700;
step=10;
}
public void start(){
Thread t= ;② // 创建多线程程序
; ③ //启动线程
}
public { ④ //线程体方法
while(true){
try{Thread.sleep(1000); }
catch(Exception e){System.out.println(e.toString());}
if(ahead[0]) y[0]=y[0]+step; else y[0]=y[0]-step;
if(y[0]>maxY) ahead[0]= false;
if(y[0] <minY) ahead[0]= true;
if(ahead[1]) y[1]=y[1]+step; else y[1]=y[1]-step;
if(y[1]>maxY) ahead[1]= false;
if(y[1] <minY) ahead[1]= true;
;⑤ //重绘APPLET,调用paint方法
}
}
public void paint(Graphics g)
{ g.setColor(Color.red);
g.drawString(ch[0],y[0],50);
g.drawString(ch[1],y[1],50);
}
}
2.Thread t=new Thread(this,name);
3.t.start();
4.void run()