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

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

问题描述

我一直在试图运行,我在命令行中创建了一个简单的小程序。我试着只是在做:

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

C:\java Applet 

这显然没有奏效;然而,我注意到,Eclipse允许我跑的小程序,如果我选择类,并选择Run As Java小程序。如何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,但使用无限制的安全策略,推出小程序(在命令行启动时的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).

要从命令行启动applet浏览器,试试这个:

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


  • 在源,在沿一个标准的applet元素的线条顶部添加注释。

  • 运行使用命令小程序查看器。搜索结果
    提示> appletviewer中TheApplet.java 搜索结果尤其值得注意,而不是提供HTML作为参数传递给小程序查看器(老办法),applet浏览器现在将直接解析applet元素出源。

  • In the source, add a comment at the top along the lines of a standard applet element.
  • Run the applet viewer using the command.

    prompt> appletviewer TheApplet.java

    Note particularly that rather than provide HTML as the argument to the applet viewer (the old way), applet viewer will now parse the applet element directly out of the source.

又见小程序的信息。页面使用applet元素在源的顶部的一个例子:例如

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文件作为小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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