请各位JAVA编程高手帮我个忙。我编的一个程序出现错误。但不知道错那里了。请你们指正。
publicclassexmm{publicstaticvoidmain(Stringagrs[]){newframe();}}classframeimplementsR...
public class exmm
{ public static void main(String agrs[])
{ new frame();
}
}
class frame implements Runnable
{ Thread student=new Thread(this);
Thread teacher=new Thread(this);
student.start();
teacher.start();
public void run()
{ if(Thread.currentThread()==student)
{ try
{System.out.println("张三正在睡觉不听课");
Thread.sleep(1000*60*60);
}
catch(InterruptedException e)
{ System.out.println("张三被老师吵醒");
}
System.out.println("张三开始听课");
}
else if(Thread.currentThread()==teacher)
{ try { System.out.println("上课!");
Thread.sleep(500);
}
catch(InterruptedException e){}
student.interrupt();
}
}
} 展开
{ public static void main(String agrs[])
{ new frame();
}
}
class frame implements Runnable
{ Thread student=new Thread(this);
Thread teacher=new Thread(this);
student.start();
teacher.start();
public void run()
{ if(Thread.currentThread()==student)
{ try
{System.out.println("张三正在睡觉不听课");
Thread.sleep(1000*60*60);
}
catch(InterruptedException e)
{ System.out.println("张三被老师吵醒");
}
System.out.println("张三开始听课");
}
else if(Thread.currentThread()==teacher)
{ try { System.out.println("上课!");
Thread.sleep(500);
}
catch(InterruptedException e){}
student.interrupt();
}
}
} 展开
展开全部
//错误已改正
public class exmm {
public static void main(String agrs[]) {
new frame();
}
}
class frame implements Runnable {
Thread student=new Thread(this);
Thread teacher=new Thread(this);
frame(){
student.start();
teacher.start();
}
public void run() {
if(Thread.currentThread()==student){
try{
System.out.println("张三正在睡觉不听课");
Thread.sleep(1000*60*60);
}
catch(InterruptedException e){
System.out.println("张三被老师吵醒");
}
System.out.println("张三开始听课");
}
else
if(Thread.currentThread()==teacher){
try {
System.out.println("上课!");
Thread.sleep(500);
}
catch(InterruptedException e){}
student.interrupt();
}
}
}
//运行结果
run:
张三正在睡觉不听课
上课!
张三被老师吵醒
张三开始听课
成功生成(总时间:0 秒)
public class exmm {
public static void main(String agrs[]) {
new frame();
}
}
class frame implements Runnable {
Thread student=new Thread(this);
Thread teacher=new Thread(this);
frame(){
student.start();
teacher.start();
}
public void run() {
if(Thread.currentThread()==student){
try{
System.out.println("张三正在睡觉不听课");
Thread.sleep(1000*60*60);
}
catch(InterruptedException e){
System.out.println("张三被老师吵醒");
}
System.out.println("张三开始听课");
}
else
if(Thread.currentThread()==teacher){
try {
System.out.println("上课!");
Thread.sleep(500);
}
catch(InterruptedException e){}
student.interrupt();
}
}
}
//运行结果
run:
张三正在睡觉不听课
上课!
张三被老师吵醒
张三开始听课
成功生成(总时间:0 秒)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询