如何转换一个Swing应用程序,以一个Applet? [英] How to convert a Swing Application to an Applet?

查看:510
本文介绍了如何转换一个Swing应用程序,以一个Applet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了Swing应用程序框架,现在我怎样才能将其转换为一个小程序桌面应用程序?主要的类扩展SingleFrameApplication。

编辑:这是启​​动类,使用的NetBeans GUI Builder的:

 公共类PhotoApp扩展SingleFrameApplication {    / **
     *在启动创建和显示应用程序的主框架。
     * /
    @覆盖保护无效启动(){
        展会(新的PhotoView(本));
    }    / **
     *此方法是通过注射资源初始化指定的窗口。
     在我们的应用中所示的Windows *来自GUI完全初始化
     *建设者,所以不需要这个额外的配置。
     * /
    @覆盖保护无效configureWindow(java.awt.Window中的根){
    }    / **
     *应用程序实例的便捷静态吸气。
     返回:PhotoUploaderApp实例
     * /
    公共静态PhotoApp getApplication(){
        返回Application.getInstance(PhotoApp.class);
    }    / **
     *主要方法启动应用程序。
     * /
    公共静态无效的主要(字串[] args){
        启动(PhotoApp.class,参数);
    }
}


解决方案

快速和肮脏的方式:

降延伸SingleFrameApplication。
添加扩展JApplet的。

替换公共无效的init构造函数()
离开身体原样。

创建一个HTML页面来保存它。并给它一个旋转。

有可能会出现一些范围的问题,但你应该能够解决那些相当容易。

I created a desktop application with Swing Application Framework, now how can I convert it to an applet? The main class extends SingleFrameApplication.

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);
    }
}

解决方案

The quick and dirty way:

Drop extends SingleFrameApplication. Add extends JApplet.

replace the constructor with public void init() leaving the body as is.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆