java关于线程的一些实例
源代码在线查看: thread6.java
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Thread6 extends Applet implements ActionListener,Runnable{
TextField tf1,tf2;
boolean boo;
int x=0;
Thread t=null;
public void init(){
t=new Thread(this);
tf1=new TextField();
tf2=new TextField();
add(tf1);
add(tf2);
tf1.addActionListener(this);
}
public void start(){
boo=false;
try{
t.start();
}catch(Exception e){}
}
public void run(){
while(true){
x=x+5;
if(x>200) x=0;
repaint();
try{
t.sleep(80);
}catch(InterruptedException e){}
if(boo){
return ;
}
}
}
public void paint(Graphics g){
g.drawString("adkjdial", x, 10);
}
public void actionPerformed(ActionEvent e){
if(tf1.getText().equals("boy")){
tf2.setText("男孩");
}
else if(tf1.getText().equals("moon")){
boo=true;
}
else {
tf2.setText("没有该单词");
}
}
}