浏览器中无法显示java plug-in

aplsc 2008-01-11 07:25:54
我编写了一个Applet程序,代码如下:

package com.aplsc.samples;

import javax.swing.*;
import java.awt.*;

public class MyApplet extends JApplet {

public void paint(Graphics g)
{
g.drawString("Hello World!",5,35);
}
}


HTML如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Hello Applet!</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

</head>
<applet
code="MyApplet.class"
width=200
height=100>
</applet>


</html>


class和html在同一个目录下,然后编译完毕后,双击这个html后,applet加载失败!
然后在MyEclipse中编辑这个html,在切换到Priview的时候,弹出对话框:
请问是怎么回事啊,谢谢了!!!JRE是6版本的
...全文
356 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
aplsc 2008-01-11
  • 打赏
  • 举报
回复
英雄啊 ,可以了。
能告诉我为什么这样吗?
huoyin 2008-01-11
  • 打赏
  • 举报
回复
MyApplet.class和test.html放在同一目录是不行的,你需要将test.html放在D:\Java\WebTest\WebRoot\WEB-INF\classes目录下,另外将test.html修改为老紫竹说得那样就行了。

你的问题在于test.html找不到applet的java类,只要把这个设置好就行了
aplsc 2008-01-11
  • 打赏
  • 举报
回复
我最后的目录结构是这样的

D:\Java\WebTest\WebRoot\WEB-INF\classes\com\aplsc\samples

MyApplet.class 和 test.html 都在samples路径下。

test.html 也是按照 你说的那个写的。问题依旧。。英雄
老紫竹 2008-01-11
  • 打赏
  • 举报
回复
html 用我的那个,加上目录
最终目录结构是这样的

test.html
com
aslsec
samples
MyApplet.class

记得是要建子目录的
aplsc 2008-01-11
  • 打赏
  • 举报
回复
class 文件 和 HTML 都是自动生成在com.aplsc.samples 这个目录下的。
不管写成
code="com.aplsc.samples.MyApplet.class"

还是
code="MyApplet.class"


都还是 加载不上去啊。
老紫竹 2008-01-11
  • 打赏
  • 举报
回复
而且,html里面的路径也得设置啊
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Hello Applet!</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

</head>
<applet
code="com.aplsc.samples.MyApplet.class"
width=200
height=100>
</applet>
</html>
老紫竹 2008-01-11
  • 打赏
  • 举报
回复
com.aplsc.samples
你的放在子目录里面啊
aplsc 2008-01-11
  • 打赏
  • 举报
回复
我看了 没有任何关于加载的信息啊。
老紫竹 2008-01-11
  • 打赏
  • 举报
回复
双击这个html后,applet加载失败

屏幕右下角应该有java 控制台,到那里看看错误输出吧!

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧