如何将 Swing 应用程序转换为 Applet?

发布于 2024-07-14 17:09:50 字数 1073 浏览 6 评论 0原文

我使用 Swing 应用程序框架创建了一个桌面应用程序,现在如何将其转换为小程序? 主类扩展了 SingleFrameApplication。

编辑:这是起始类,使用 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);
    }
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

为你拒绝所有暧昧 2024-07-21 17:09:50

快速但肮脏的方法:

Drop 扩展 SingleFrameApplication。
添加扩展 JApplet。

将构造函数替换为 public void init()
让身体保持原样。

创建一个 HTML 页面来保存它。 并尝试一下。

可能会出现一些范围问题,但您应该能够相当轻松地解决这些问题。

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.

岁月苍老的讽刺 2024-07-21 17:09:50

最简单的事情就是创建一个继承自 JApplet 的新外部类,并实例化其中的实际框架。

更新

发现在线教程可以提供帮助。

Simplest thing is just to make a new outer class inheriting from JApplet, and instantiate the actual frame inside it.

Update

Found a tutorial online that could help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文