原代码如下:
package shape;public class SubThread extends Thread {
private long startTime,endTime;
private Runnable target;
private String name;
private int xpos,ypos=200;

public SubThread(Runnable target,String name)
{
this.target=target;
this.name=name;
}

public void setXpos(int xpos)
{
this.xpos=xpos;
}

public  void setYpos(int ypos)
{
this.ypos=ypos;
}

public int getYpos()
{
return this.ypos;
}

public int getXpos()
{
return this.xpos;
}

public   long getTime(long startTime,long endTime)
{
return endTime-startTime;
}
}package shape;import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.*;public class ShapeTemp extends Applet implements Runnable{
SubThread magenta,green,pink,yellow;
Map map=new HashMap();
public void init()
{
this.resize(280,230);
}

public void start()
{
magenta=new SubThread(this,"magenta");
magenta.setXpos(20);
map.put("magenta", magenta);
magenta.start();

   
 
green=new SubThread(this,"green");
    green.setXpos(60);
    map.put("green", green);
    green.start();
  pink=new SubThread(this,"pink");
    pink.setXpos(100);
    map.put("pink", pink);
    pink.start();
 
    yellow=new SubThread(this,"yellow");
    yellow.setXpos(140);
    map.put("yellow", yellow);
    yellow.start();
 System.out.println("successful create!"); //经过测试,这一句执行了。可为什么public void run()方法执行不了??
}

public void stop()
{
if(magenta!=null)
{   magenta.stop(); }
if(green!=null)
{   green.stop();  }
if(pink!=null)
{   pink.stop();   }
    if(yellow!=null)
    {   yellow.stop(); }  
    map.clear();
}

public void run()
{   System.out.println("running......");//这句不知道为什么没有执行??不是thread类的start()方法就可以调用run()方法吗?而SubThread类继承thread类,其run()方法就应该执行呀?
String threadName=Thread.currentThread().getName();
System.out.println("current  is: "+threadName);
SubThread currentThread=(SubThread)map.get(threadName);
while((currentThread.getYpos()-10)>=30)
{
currentThread.setYpos(currentThread.getYpos()-10);
repaint(); 
try
{
Thread.sleep((int)(Math.random()*3000));
}
catch(InterruptedException ie)
{ }
}

}


public void paint(Graphics g)
{
g.setColor(Color.red);
g.drawLine(10,30,270,30);
g.setColor(Color.magenta);
if(map.get("magenta")==null)
g.fillRect(20,200,10,10);
else
g.fillRect(((SubThread)map.get("magenta")).getXpos(),((SubThread)map.get("magenta")).getYpos(),10,10);
g.setColor(Color.green);
if(map.get("green")==null)
g.fillRect(60,200,10,10);
else
    g.fillRect(((SubThread)map.get("green")).getXpos(),((SubThread)map.get("green")).getYpos(),10,10);
g.setColor(Color.pink);
if(map.get("pink")==null)
g.fillRect(100,200,10,10);
else
g.fillRect(((SubThread)map.get("pink")).getXpos(),((SubThread)map.get("pink")).getYpos(),10,10);
g.setColor(Color.yellow);
if(map.get("yellow")==null)
g.fillRect(140,200,10,10);
else
g.fillRect(((SubThread)map.get("yellow")).getXpos(),((SubThread)map.get("yellow")).getYpos(),10,10); g.setColor(Color.black);
g.drawString("successful1!",180,80);
g.drawString("successful2!",180,120);
g.drawString("successful3!",180,160);
g.drawString("successful4!",180,200);
}

}说明:程序运行时,后台只输出“successful create!”,四个小方块不向上移动,而其run()方法不执行?不知道为什么??谢谢大家了!!