Java applet-> ClassNotFound异常 [英] Java applet --> ClassNotFound Exception

查看:292
本文介绍了Java applet-> ClassNotFound异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Java并正在阅读这本书:

现在这是我的html代码:

<!DOCTYPE html>
<html>


<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>


<body>
<applet code = "packageteste.Relogio.class" width="700"></applet>
</body>


</html>

另请参见此处:如何正确指定代码库并在Java applet中存档?

I'm learning Java and reading this book: https://www.fca.pt/cgi-bin/fca_main.cgi/?op=2&isbn=978-972-722-791-4.

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 :

<!DOCTYPE html>
<html>


<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>


<body>
<applet code = "packageteste.Relogio.class" width="700"></applet>
</body>


</html>

解决方案

  • 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.

See also here: How to specify correctly codebase and archive in Java applet?

这篇关于Java applet-> ClassNotFound异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆