浏览器打开含有applet标签网页报ClassNotFoundException错误的解决办法
来源:互联网 发布:java中文api下载 编辑:程序博客网 时间:2024/06/16 21:59
----------------------------------~~~~~~~~~~~~~~~上班太无聊,闲的我开始重新学JAVA~~~~~~~~~~~--------------------------------------------------
先贴上applet代码:气泡上升示例
package applet;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Image;
import javax.management.loading.PrivateClassLoader;
@SuppressWarnings("serial")
public class applet extends Applet implements Runnable {
Thread artisThread=null;
int bubble=0,thisbubble=0;
int MAXBUBBLIES=20;
int stepper=4;
int record[][]=new int [MAXBUBBLIES][7];
public void init(){
resize(400,400);
}
public void draw_bubble(int thisbubble,Graphics g)
{
record[thisbubble][0]=(int)(Math.random()*400);
record[thisbubble][1]=400;
record[thisbubble][2]=(int)(Math.random()*100)/2;
record[thisbubble][3]=(int)(Math.random()*255);
record[thisbubble][4]=(int)(Math.random()*255);
record[thisbubble][5]=(int)(Math.random()*8);
record[thisbubble][6]=(int)(Math.random()*10);
Color col= new Color(record[thisbubble][3], record[thisbubble][4],255);
g.setColor(col);
g.fillOval(record[thisbubble][0], record[thisbubble][1], record[thisbubble][2],record[ thisbubble][2]);
}
public void move_bubble(int x,int y,int r,Color col,int step,int step2,Graphics g)
{
g.setColor(Color.white);
g.fillOval(x, y, r, r);
g.setColor(col);
g.fillOval(x-step, y-step2, r, r);
}
public void paint(Graphics g)
{
int i,j,tmp;
if(bubble<MAXBUBBLIES || thisbubble<MAXBUBBLIES)
{
draw_bubble( thisbubble, g);
if(bubble< MAXBUBBLIES)
{
bubble++;
thisbubble++;
}
else
thisbubble=MAXBUBBLIES;
}
for (i=0;i<bubble;++i)
{
if(i%5<=stepper)
{
move_bubble( record[i][0], record[i][1], record[i][2],
new Color(record[i][3], record[i][4],255),record[i][5],record[i][6],g);
record[i][0]-=record[i][5];
record[i][1]-=record[i][6];
if(record[i][0]+2* record[i][2]<0||record[i][1]+2* record[i][2]<0)
{
draw_bubble(i, g);
}
}
}
}
public void update (Graphics g)
{
paint(g);
g.drawImage(null,100,100,null);
}
public void start()
{
if(artisThread==null )
{
artisThread=new Thread(this);
artisThread.start();
}
}
public void stop()
{
artisThread=null;
}
@Override
public void run() {
// TODO Auto-generated method stub
while(true)
{
repaint();
try {
artisThread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
效果如下
在applet.class文件所在目录放入html文件
<html>
<head>
<title>AnApplet</title>
</head>
<body>
<applet code = "applet.class" width = 400 height = 400>
</applet>
</body>
</html>
结果使用IE浏览器打开的时候报ClassNotFoundException错误,经过摸索,解决方法有两个:
一、code改为包.类名.class,同时把html文件放到和包一个目录下,增加包的相对路径,code_base,html文件更改如下:
<html>
<head>
<title>AnApplet</title>
</head>
<body>
<applet code_base="applet/" code = "applet.applet.class" width = 400 height = 400>
</applet>
</body>
</html>
二、把包改成默认包,同时去掉package applet,重新生成class文件,把html文件放入和class文件同一目录下,html内容如下:
<html>
<head>
<title>AnApplet</title>
</head>
<body>
<applet code = "applet.class" code_base="/" width = 400 height = 400>
</applet>
</body>
</html>
经验证,两个方法都可以解决ClassNotFoundException的问题。
- 浏览器打开含有applet标签网页报ClassNotFoundException错误的解决办法
- Maven项目下报错误java.lang.ClassNotFoundException的解决办法
- javascript判断浏览器是否含有支持applet的JRE环境
- Win8.1 IE11 浏览器无法打开任何网页的解决办法
- 在网页中使用Applet的标签
- 在网页中使用Applet的标签
- Applet按钮打开网页
- 打开EXCEL时,报XML错误的解决办法
- 浏览器报ERR_CONNECTION_RESET错误的分析和解决办法
- 解决applet不能在浏览器中打开的问题
- IE打开含Applet的网页自动关闭
- 有关百度一键分享链接到微信朋友圈无法打开网页,报404错误的解决办法,from=timeline&isappinstalled=0,和伪静态规则有关
- 浏览器中运行applet报错的处理之道
- 在网页中使用Applet的标签详解
- 在网页中使用Applet的标签详解
- 在网页中使用Applet的标签详解
- 如何设置谷歌Chrome浏览器打开新的标签页为指定网页?
- 谷歌浏览器怎么拖动链接打开一个新的标签网页啊?
- UVA1629[Cake slicing] 棋盘动态规划
- SQL优化
- SpringBoot应用与原理之开发环境搭建
- EL表达式和JSTL常用学习
- 深度学习caffe平台-----裁剪层(Crop Layer)参数及参数详解
- 浏览器打开含有applet标签网页报ClassNotFoundException错误的解决办法
- centos libc.6.so 链接出错
- C++ 学习笔记
- Nginx出现could not open error log file (permission denied)报错
- C#中怎样实现序列化和反序列化
- 大型网站架构之分布式消息队列
- numpy 数组和矩阵的乘法的理解
- SYN攻击(DDOS攻击的一种)
- 8月份遇到web项目问题总结