Eclipse如何运行.java文件作为applet? [英] How does Eclipse run .java files as applets?

查看:738
本文介绍了Eclipse如何运行.java文件作为applet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试运行一个我从命令行创建的一个简单的applet。我试着做:

I've been trying to run a simple applet that I created from the command line. I tried just doing:

C:\java Applet 

显然没有工作;但是,我注意到,如果我选择该类并选择以java applet运行,Eclipse可以让我运行applet。 Eclipse如何做到这一点?

It obviously didn't work; however, I noticed that Eclipse lets me run the applet if I select the class and select run as java applet. How does Eclipse do this?

推荐答案

我相信IDE通常使用appletviewer启动applet,但是使用无限制的安全策略(appletviewer从命令行启动时为沙盒)

I believe IDEs typically launch applets using the appletviewer, but using an unrestricted security policy (the appletviewer when launched from the command line is sand-boxed).

要从命令行启动小程序查看器,请尝试:

To launch the applet viewer from the command line, try this:


  • 在源中,沿着标准applet元素的行添加注释。

  • 使用该命令运行applet查看器。


    提示> appletviewer TheApplet.java

    特别要注意的是,applet查看器不会将HTML作为applet查看器的参数(旧方式),而是直接从源代码中解析出applet元素。

另见小程序信息。页面,用于在源的顶部使用applet元素的示例:EG

See also the applet info. page for an example of using the applet element at the top of the source: E.G.

/* <!-- Defines the applet element used by the appletviewer. -->
<applet code='HelloWorld' width='200' height='100'></applet> */
import javax.swing.*;

/** An 'Hello World' Swing based applet.

To compile and launch:
prompt> javac HelloWorld.java
prompt> appletviewer HelloWorld.java  */
public class HelloWorld extends JApplet {

    public void init() {
        // Swing operations need to be performed on the EDT.
        // The Runnable/invokeLater() ensures that happens.
        Runnable r = new Runnable() {
            public void run() {
                // the crux of this simple applet
                getContentPane().add( new JLabel("Hello World!") );
            }
        };
        SwingUtilities.invokeLater(r);
    }
}

从命令行启动时,小程序查看器将具有比在浏览器中部署的小应用程序更加限制的沙盒。

When launched from the command line, the applet viewer will have an even more restrictive sand-box than is applied to an applet deployed in a browser.

appletviewer的替代方法是 Appleteer ,我可以强烈推荐,因为它比appletviewer好(我写了它)。

An alternative to appletviewer is Appleteer which I can highly recommend, because it is better than appletviewer ( and I wrote it ;).

这篇关于Eclipse如何运行.java文件作为applet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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