直接运行 Java-applet(不带 html 页面)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3012124/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 23:55:53  来源:igfitidea点击:

Run Java-applets directly ( without html page )

javaapplet

提问by PleaseHelpMe

I have a problem.

我有个问题。

How i can run my java-applet directly without embedded in my web page?

如何在不嵌入网页的情况下直接运行我的 java-applet?

I know appletViewr can execute applet without a browser but I need to get java applet without html page.

我知道 appletViewr 可以在没有浏览器的情况下执行小程序,但我需要在没有 html 页面的情况下获取 java 小程序。

回答by spgodara

Use below code with your code, where AppletClass is your Applet class.

将以下代码与您的代码一起使用,其中 AppletClass 是您的 Applet 类。

AppletClass appletClass = new AppletClass ();

JFrame frame = new JFrame();
frame.setLayout(new GridLayout(1, 1));
frame.add(appletClass );

// Set frame size and other properties
...

// Call applet methods
appletClass .init();
appletClass .start();

frame.setVisible(true);

More customizations can be done as required.

可以根据需要进行更多自定义。

回答by aioobe

Appletviewer is the way to go, BUT, it still requires a webpage with an applet-tag.

Appletviewer 是可行的方法,但是,它仍然需要一个带有 applet-tag 的网页

An alternative solution is to write a stub class, with a main method, that instantiates the applet, calls init(), start(), stop()and destroy()as would otherwise have been done by the browser or appletviewer.

另一种解决方案是写一个存根类,它有一个主要方法,实例化的小应用程序,电话init()start()stop()destroy()为原本已经被浏览器或appletviewer中完成。

回答by springfeld

Build a subclass, which implements main-method, and call init(), start(), stop(), destroy as needed.

构建一个实现main-method的子类,并根据需要调用init()、start()、stop()、destroy。

回答by Justin

If you use eclipse: Right-Click on your main java file (the one which extends Applet), select the 'Run As' submenu, and select 'Applet.

如果您使用 eclipse:右键单击您的主 Java 文件(扩展 Applet 的文件),选择“运行方式”子菜单,然后选择“Applet”。

回答by Pratik M.

Use /*<applet code="java file name " height=150 width=150></applet>*/before declaring applet class and then compile java program and run applet by using appletviewer it execute perfectly don't require any html file

/*<applet code="java file name " height=150 width=150></applet>*/在声明applet类之前使用然后编译java程序并使用appletviewer运行applet它完美执行不需要任何html文件

回答by stacker

Run appletviewer [ options ] urls ...

运行appletviewer [ options ] urls ..

Documentation

文档

回答by JADAV AKASH

<applet code=classname height=200 width=200>

</applet>

Simply write this code in your java program and first run using:

只需在您的 Java 程序中编写此代码并首先使用以下命令运行:

javac classname.java

after

run:appletviewer classname.java