|
楼主 |
发表于 2004-9-6 22:13:38
|
显示全部楼层
谢谢,问题解决,药到病除!
package Threader;
import java.awt.*;
public class Threader extends Canvas implements Runnable
{
int myPosition =0;
String myName;
int numberofSteps=600;
boolean keepRunning =true;
public Threader (String inName)
{ myName=new String (inName); }
public synchronized void paint(Graphics g)
{ g.setColor (Color.black);
g.drawLine (0,getSize().height/2,getSize().width,getSize().height/2);
g.setColor (Color.yellow);
g.fillOval((myPosition*getSize().width/numberofSteps),0, 15,getSize().height);
}
public void stop()
{ keepRunning = false; }
public void run()
{ while (myPosition <numberofSteps)
myPosition=myPosition+1; }
}
import java.awt.*;
import java.applet.*;
import Threader.Threader;
public class testThread extends Applet implements Runnable
{
Threader theRacers[];
static int racerCount = 3;
Thread theThreads[];
Thread thisThread;
static boolean inApplet=true;
int numberofThreadsAtStart;
public void init()
{
numberofThreadsAtStart = Thread.activeCount();
setLayout(new GridLayout(racerCount,1));
theRacers = new Threader [racerCount];
theThreads = new Thread[racerCount];
for (int x=0;x<numberofThreadsAtStart;x=x+2)
{
try
{
thisThread.sleep(100);
}
catch (InterruptedException e)
{
System.out.println("thisThread was interrupted");
}
}
if (inApplet)
{
stop();
destroy();
}
else
System.exit(0);
}
public static void main (String argv[])
{
inApplet=false;
if (argv.length>0)
racerCount = Integer.parseInt(argv[0]);
Frame theFrame = new Frame("The Great Thread Race");
testThread theRace = new testThread();
theFrame.setSize(400,200);
theFrame.add ("Center",theRace);
theFrame.show();
theRace.init();
theFrame.pack();
theRace.start();
}
}
出现下面的错误,怎么回事?
--------------------Configuration: j2sdk1.4.2 <Default>--------------------
testThread.java:5: testThread is not abstract and does not override abstract method run() in java.lang.Runnable
public class testThread extends Applet implements Runnable
^
1 error
Process completed. |
|