如何将 Swing 应用程序转换为 Applet? [英] How to convert a Swing Application to an Applet?
问题描述
我使用 Swing 应用程序框架创建了一个桌面应用程序,现在如何将其转换为小程序?主类扩展了 SingleFrameApplication.
I created a desktop application with Swing Application Framework, now how can I convert it to an applet? The main class extends SingleFrameApplication.
这是起始类,使用 NetBeans GUI 构建器:
EDITED: This is the starting class, used NetBeans GUI builder:
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);
}
}
推荐答案
又快又脏的方法:
Drop 扩展了 SingleFrameApplication.添加扩展 JApplet.
Drop extends SingleFrameApplication. Add extends JApplet.
用 public void init() 替换构造函数保持身体原样.
replace the constructor with public void init() leaving the body as is.
创建一个 HTML 页面来保存它.试一试.
Create an HTML page to hold it. and give it a whirl.
可能会出现一些范围界定问题,但您应该能够轻松解决这些问题.
There will likely be some scoping issues, but you should be able to fix those fairly easily.
这篇关于如何将 Swing 应用程序转换为 Applet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!