java applet class not found,Java applet-> ClassNotFound异常

博客讲述了Java Applet练习中,在Eclipse的appletviewer能正常运行,但集成到HTML时遇到问题。给出了Java代码和HTML代码,并提供解决方案,如code属性不能包含.class,若有.jar文件需用archive属性指定,无.jar文件要确保类文件路径正确。

In this book, I have a Java applet exercise. I can run it in Eclipse in appletviewer and works well. but I'm having trouble integrating the applet into HTML.

Here's my java code:

package packageteste;

import java.applet.Applet;

import java.awt.Color;

import java.awt.Font;

import java.awt.Graphics;

import java.util.Date;

public class Relogio extends Applet implements Runnable{

Date data;

Thread proc;

Font f = new Font("TimesRoman", Font.BOLD, 40);

public void start(){

proc = new Thread(this);

proc.start();

}

public void stop(){

proc = null;

}

@SuppressWarnings("static-access")

@Override

public void run() {

Thread th = Thread.currentThread();

while(proc == th){

data = new Date();

try{

th.sleep(500);

}catch(InterruptedException e){}

repaint();

}

}

public void paint(Graphics g){

g.setFont(f);

g.setColor(Color.GREEN);

g.drawString(data.toString(),20,60);

}}

And now here's my html code :

Insert title here

解决方案

code = "packageteste.Relogio.class" must not include .class

If you have your applet built into a .jar file use the archive="..." attribute to tell the browser what .jar it is.

If you don't have a .jar make sure the class packageteste.Relogio can be found as Relogio.class in the packageteste directory.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值