run as java applet,Eclipse如何运行.java文件作为applet?

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

C:\java Applet

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?

解决方案

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:

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.

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

/*

*/

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.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值