2013-05-28 36 views
2

你好,我曾尝试下面的代码如何使用Web项目

的index.jsp

<applet code="com.applet.PrintApplet" codebase ="TestApplet.jar" width="320" height="120"></applet> 

Java类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); 
    } 

} 

当在Eclipse中运行小程序此应用程序在浏览器中运行,然后

类未发现异常被触发..

,但我在浏览器

错误,如三个按钮

详细一个弹出框的问题忽略和重新加载

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文件。

回答

2

你有两个选择:
1.使用appletviewer附带你的JDK只是看到一个最基本的浏览器
2.嵌入applet标记在HTML页面中的小应用程序的工作。

<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接受的答案。

相关问题