如何使用web项目在Eclipse中运行小程序 [英] How to run applet in eclipse using web project

查看:247
本文介绍了如何使用web项目在Eclipse中运行小程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我曾尝试以下code

Hello I have tried the following code

的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);
   }

}

在此应用程序在浏览器中运行然后

when this application runs in browser then

类未发现异常被激发。

但我有在浏览器的问题。

but i have problem in browser

错误一样有三个按钮,弹出框

详细忽略和刷新

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

and i have added jar file in build path also.

推荐答案

您有两种选择:结果
1.使用附带的JDK 的appletviewer 来只看到一个最基本的浏览器搜索的小程序工作
2.嵌入applet标记的HTML页面。

You have two options:
1. to use appletviewer which comes with your JDK to just see the applet work in a bare-bones browser
2. embed the applet tag in your HTML page.

<html>
    <title>My Applet</title>
    <body>
        <applet code="PrintApplet.class" width="400" height="400"></applet>
    </body>
</html>  

但因为它的立场,&LT;小程序方式&gt; 已去precated结果
所以,这里是你做什么:结果
1.添加到您的&LT; HEAD&GT; &LT;脚本SRC =htt​​p://java.com/js/deployJava.js &GT;&LT; / SCRIPT&GT; 结果
2.添加到您的&LT;身体GT;

But as it stands, <applet> has been deprecated.
So, here is what you do:
1. Add this to your <head> : <script src="http://java.com/js/deployJava.js"></script>
2. Add this to your <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的,&LT; HEAD&GT; 则不需要,所以你可以只输入&LT;脚本&GT; ...&LT; / SCRIPT&GT;

Again, as of HTML5, <head> is not needed so you can just type <script>....</script>

这是取自的回答。

这篇关于如何使用web项目在Eclipse中运行小程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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