import java.awt.Graphics;
import java.util.Date;public class ep7_3 extends java.applet.Applet implements Runnable{
Thread clockThread;
public void start(){
if(clockThread == null){
clockThread = new Thread(this,"Clock");
clockThread.start();
}
}
public void run(){
while(clockThread != null){
repaint();
try{
clockThread.sleep(1000);
}catch(InterruptedException e){
}
}
}
public void paint(Graphics g){
Date now = new Date();
g.drawString(now.getHours()+":"+now.getMinutes()+":"+now.getSeconds(),5,10);
}
public void stop(){
clockThread.stop();
clockThread = null;
}
}
<html>
<head><title>时钟</title></head>
<body>
<applet codebase = "." code = "./classes/ep7_3.class" name = "" width = "200" height = "100"></applet>
</body>
</html>这段代码 加上一个简短的html 怎么实现不了 显示时钟的功能 请各位大侠 帮组解决该问题
import java.util.Date;public class ep7_3 extends java.applet.Applet implements Runnable{
Thread clockThread;
public void start(){
if(clockThread == null){
clockThread = new Thread(this,"Clock");
clockThread.start();
}
}
public void run(){
while(clockThread != null){
repaint();
try{
clockThread.sleep(1000);
}catch(InterruptedException e){
}
}
}
public void paint(Graphics g){
Date now = new Date();
g.drawString(now.getHours()+":"+now.getMinutes()+":"+now.getSeconds(),5,10);
}
public void stop(){
clockThread.stop();
clockThread = null;
}
}
<html>
<head><title>时钟</title></head>
<body>
<applet codebase = "." code = "./classes/ep7_3.class" name = "" width = "200" height = "100"></applet>
</body>
</html>这段代码 加上一个简短的html 怎么实现不了 显示时钟的功能 请各位大侠 帮组解决该问题
Applet部署的时候,要注意很多东西。
首先IE浏览器对Applet标签的支持不是很好。
如果你使用FireFox浏览器,类文件(.class文件)和html文件放同级目录,同时类定义在默认包中,则页面中的标签这样写就OK了。
<applet codebase = "." code = "ep7_3" name = "" width = "200" height = "100"></applet>
这样不对吗?