您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Eclipse如何将.java文件作为applet运行?

Eclipse如何将.java文件作为applet运行?

我相信IDE通常会使用appletviewer来启动applet,但是会使用不受限制的安全策略(从命令行启动时appletviewer会被沙盒化)。

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

prompt> appletviewer TheApplet.java

特别要注意的是,小应用程序查看器现在不直接将HTML作为小程序查看器的参数来提供参数,而是将解析小程序元素直接从源中解析出来。

另请参阅小程序信息在源顶部使用小程序元素的示例的页面:EG

/* <!-- 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);
    }
}

当从命令行启动时,小应用程序查看器将具有比应用于浏览器中部署的小应用程序更严格的沙箱。

我强烈推荐Appleteer,它是appletviewer的替代方法,因为它比appletviewer更好(我写过它;)。

java 2022/1/1 18:25:15 有564人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶