编译后,出现14个错误,我修改了7个,还有7个不明白是什么原因,想高手给分析一下。

candy811114 2005-06-14 04:14:18
其实我是按书来打出来的
其运行是在HTML上加上<applet code = .....>,然后通过HTML页面打开来看的
但是在编译的时候,却出现错误,我不明白个中道理,想请高手给分析一下,为什么会出现这样的错误。
程序如下:

import java.applet.Applet.*;
import java.awt.*;

public class TextRunnable extends Applet implements Runnable
{
Label prompt1 = new Label("子线程1");
Label prompt2 = new Label("子线程2");
TextField threadfirst = new TextField(25);
TextField threadsecond = new TextField(25);
Thread thread1,thread2;
int count1;
int count2;

public void init()
{
add(prompt1);
add(prompt2);
add(threadfirst);
add(threadsecond);
}

public void start()
{
Thread thread1 = new Thread(this,"FirstThread");
Thread thread2 = new Thread(this,"SecondThread");
thread1.start();
thread2.start();
}

public void run()
{
String currentRunning;
while (true)
{
try
{
Thread.sleep((int)(Math.random()*100));
}
catch (InterruptedException e)
{
}
currentRunning = Thread.currentThread().getName();
if (currentRunning.equals("FirstThread"))
{
count1++;
threadfirst.setText("线程1第"+count1+"次被调度");
}
else if (currentRunning.equals("SecondThread"))
{
count2++;
threadsecond.setText("线程2第"+count2+"次被调度");
}
}
}
}
...全文
137 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
candy811114 2005-06-17
  • 打赏
  • 举报
回复
好 结帖了啦 谢谢各位
candy811114 2005-06-17
  • 打赏
  • 举报
回复
啊。。感谢啦
不过得问一下,如何结帖啊??我不想减声誉
laughsmile 2005-06-14
  • 打赏
  • 举报
回复
强烈建议使用eclipse来进行java开发,一看编译器的调试信息,基本的错误都一清二楚了:)
http://www.eclipse.org/downloads/index.php
kingdoom 2005-06-14
  • 打赏
  • 举报
回复
用JB OR ECLIPSE 的话 一些问题他会给你提示,你可以先用 jc 错误了后先上eclipse如果有什么不懂得在问吧
GaryZhu 2005-06-14
  • 打赏
  • 举报
回复
import java.applet.Applet;
candy811114 2005-06-14
  • 打赏
  • 举报
回复
感谢上面各位老大了
candy811114 2005-06-14
  • 打赏
  • 举报
回复
1个地方就产生这么多错误啊??
好象涉及到applet的都出现错误了啦。。。
candy811114 2005-06-14
  • 打赏
  • 举报
回复
scottwhb 2005-06-14
  • 打赏
  • 举报
回复
import java.applet.*;
hujiaboy 2005-06-14
  • 打赏
  • 举报
回复
import java.applet.Applet.*;
===>
import java.applet.*;
bitiliu 2005-06-14
  • 打赏
  • 举报
回复
呵呵,这个我可以告诉你!
程序的第一行改为:
import java.applet.*;
就可以了!
candy811114 2005-06-14
  • 打赏
  • 举报
回复
能帮我看下是什么原因吗??
非常希望你能授我以渔。。。。。。。。
candy811114 2005-06-14
  • 打赏
  • 举报
回复
D:\java\0613>javac TextRunnable.java
TextRunnable.java:4: cannot resolve symbol
symbol : class Applet
location: class TextRunnable
public class TextRunnable extends Applet implements Runnable
^
TextRunnable.java:16: cannot resolve symbol
symbol : method add (java.awt.Label)
location: class TextRunnable
add(prompt1);
^
TextRunnable.java:17: cannot resolve symbol
symbol : method add (java.awt.Label)
location: class TextRunnable
add(prompt2);
^
TextRunnable.java:18: cannot resolve symbol
symbol : method add (java.awt.TextField)
location: class TextRunnable
add(threadfirst);
^
TextRunnable.java:19: cannot resolve symbol
symbol : method add (java.awt.TextField)
location: class TextRunnable
add(threadsecond);
^
TextRunnable.java:24: reference to Thread is ambiguous, both method Thread(java.
lang.ThreadGroup,java.lang.String) in java.lang.Thread and method Thread(java.la
ng.Runnable,java.lang.String) in java.lang.Thread match
Thread thread1 = new Thread(this,"FirstThread");
^
TextRunnable.java:25: reference to Thread is ambiguous, both method Thread(java.
lang.ThreadGroup,java.lang.String) in java.lang.Thread and method Thread(java.la
ng.Runnable,java.lang.String) in java.lang.Thread match
Thread thread2 = new Thread(this,"SecondThread");
^
7 errors
darkattack 2005-06-14
  • 打赏
  • 举报
回复
你的编译错误信息呢?

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧