小编典典
我相信IDE通常会使用appletviewer来启动applet,但是会使用不受限制的安全策略(从命令行启动时appletviewer会被沙盒化)。
要从命令行启动小程序查看器,请尝试以下操作:
在源代码中,沿着标准applet元素在顶部添加注释。
使用命令运行小程序查看器。
prompt> appletviewer TheApplet.java
特别要注意的是,小应用程序查看器现在不直接将HTML作为小程序查看器的参数来提供参数,而是将解析小程序元素直接从源中解析出来。
另请参阅小程序信息在源顶部使用小程序元素的示例的页面:EG
/*
*/
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更好(我写过它;)。
2020-11-26