问题描述
importjava.util.*;importjava.awt.*;importjava.awt.event.*;importjava.applet.*;publicclasshuminextendsAppletimplementsRunnable{privateButtonbut;privateLabellab;privateBooleanisRun;privateThreadthrobj;publichuminapplet;publicvoidinti(){isRun=false;this.setLayout(null);but=newButton("start");but.setBounds(100,100,100,30);but.setBackground(Color.red);but.addMouseListener(newmyMouseAdapter());this.add(but);lab=newLabel();lab.setBounds(60,50,180,30);lab.setAlignment(Label.CENTER);this.add(lab);this.setBackground(Color.cyan);this.setBounds(100,150,310,150);this.setVisible(true);}publicclassmyMouseAdapterextendsMouseAdapter{publicvoidmouseClicked(MouseEvente){if(isRun==true){isRun=false;//将导致现在的run的那个电子钟Thread自动停止}else{isRun=true;throbj=newThread(applet);throbj.start();}if(isRun)but.setLabel("stop");elsebut.setLabel("start");}}publicvoidstart(){applet=this;}publicvoidstop(){/*希望离开此网页时,停止电子钟Thread,用appletviewer执行此网页*/isRun=false;/*若无此句,此Applet停止时,电子钟Thread有可能还在run*/but.setLabel("sttart");}publicvoiddestroy(){}publicvoidrun(){Calendarcalendar=newGregorianCalendar();//创建一个Calendar;while(isRun){calendar.setTimeInMillis(System.currentTimeMillis());/*取得系统现在时间,来设置此Calendar现在显示的日期时间,Calendar显示的时间不会自动改变*得利用setTitle()或setTimeInMillis()来设置它显示的日期时间。如同撕日历或翻日历一般*/lab.setText(calendar.get(Calendar.YEAR)+"年"+(calendar.get(Calendar.MONTH)+1)+"月"+calendar.get(Calendar.DATE)+"日"+calendar.get(Calendar.HOUR_OF_DAY)+"时"+calendar.get(Calendar.MINUTE)+"分"+calendar.get(Calendar.SECOND)+"秒");/*由此Calendar取得年,月,日,时,分,秒之值,如同查看日历现在显示的日期时间一般*/try{Thread.sleep(900);//休眠0.9秒}catch(Exceptione){}}}}<HTML><HEAD><TITLE>多线程的Applet程序</TITLE></HEAD><BODY><APPLETCODE="humin.class"WIDTH=300HEIGHT=150></APPLET><?BODY></HTML>程序没有错误,可就是运行时出错啊跪求!
解决方案
解决方案二:
是用浏览器来运行的,noteclipse
解决方案三:
浏览器有<Applet>标签是用来运行这个的.