java 如何将 Swing 应用程序转换为 Applet?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/651470/
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
How to convert a Swing Application to an Applet?
提问by fromvega
I created a desktop application with Swing Application Framework, now how can I convert it to an applet? The main class extends SingleFrameApplication.
我使用 Swing 应用程序框架创建了一个桌面应用程序,现在如何将其转换为小程序?主类扩展了 SingleFrameApplication。
EDITED: This is the starting class, used NetBeans GUI builder:
编辑:这是起始类,使用 NetBeans GUI 构建器:
public class PhotoApp extends SingleFrameApplication {
/**
* At startup create and show the main frame of the application.
*/
@Override protected void startup() {
show(new PhotoView(this));
}
/**
* This method is to initialize the specified window by injecting resources.
* Windows shown in our application come fully initialized from the GUI
* builder, so this additional configuration is not needed.
*/
@Override protected void configureWindow(java.awt.Window root) {
}
/**
* A convenient static getter for the application instance.
* @return the instance of PhotoUploaderApp
*/
public static PhotoApp getApplication() {
return Application.getInstance(PhotoApp.class);
}
/**
* Main method launching the application.
*/
public static void main(String[] args) {
launch(PhotoApp.class, args);
}
}
回答by Chris Cudmore
The quick and dirty way:
快速而肮脏的方式:
Drop extends SingleFrameApplication. Add extends JApplet.
Drop 扩展了 SingleFrameApplication。添加扩展 JApplet。
replace the constructor with public void init() leaving the body as is.
用 public void init() 替换构造函数,使主体保持原样。
Create an HTML page to hold it. and give it a whirl.
创建一个 HTML 页面来保存它。试一试。
There will likely be some scoping issues, but you should be able to fix those fairly easily.
可能会有一些范围界定问题,但您应该能够很容易地解决这些问题。

