您好我已尝试过以下代码
的index.jsp
<applet code="com.applet.PrintApplet" codebase ="TestApplet.jar" width="320" height="120"></applet>
java class PrintApplet.java
import java.applet.Applet;
import java.awt.Color;
public class PrintApplet extends Applet{
public void paint(Graphics g){
g.drawString("Welcome in Java Applet.",40,20);
}
}
此应用程序在浏览器中运行时
未找到类的异常被触发..
但我在浏览器中遇到问题
错误,如带有三个按钮的弹出框
详细信息忽略并重新加载
Application error
classNotFoundException
com.applet.printApplet
详情按钮
Java Plug-in 10.21.2.11
Using JRE version 1.7.0_21-b11 Java HotSpot(TM) Client VM
User home directory = C:\Users\Helthcare2
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
我也在构建路径中添加了jar文件。
答案 0 :(得分:2)
您有两种选择:
1.使用JDK附带的appletviewer
只看到applet在一个简单的浏览器中工作
2.在您的HTML页面中嵌入applet标记。
<html>
<title>My Applet</title>
<body>
<applet code="PrintApplet.class" width="400" height="400"></applet>
</body>
</html>
但就目前而言,<applet>
已被弃用
那么,这就是你做的:
1.将其添加到<head>
:<script src="http://java.com/js/deployJava.js"></script>
2.将其添加到您的<body>
:
<script>
var attributes = {codebase:'http://my.url/my/path/to/codebase',
code:'my.main.Applet.class',
archive: 'my-archive.jar',
width: '800',
height: '600'};
var parameters = {java_arguments: '-Xmx256m'}; // customize per your needs
var version = '1.5' ; // JDK version
deployJava.runApplet(attributes, parameters, version);
</script>
同样,从HTML5开始,不需要<head>
,因此您只需输入<script>....</script>
这取自:Embedding Java Applet into .html file接受的答案。