You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Java应用全屏模式下第二窗口的创建与初始化方案咨询

Java应用全屏模式下第二窗口的创建与初始化方案咨询

我在Stack Overflow上看到了一些关于Java应用实现全屏模式的建议,其中最常见的方案是创建第二个JFrame,然后把应用的主内容面板迁移过去。

理论上来说,这应该在我正在维护的现有项目分支里很好实现,因为应用的所有内容确实都集中在一个单独的面板中。

但我现在纠结的是,到底该如何正确设置这个第二窗口。

目前主窗口的.java文件结构大概是这样的:

public class mainFrame extends JFrame {

  // variable declarations

  init {
    // panel content is initialized here
    // size of mainFrame is set here
    // pack() is called here
    // position of mainFrame is set here
    // mainFrame is made visible here
  }

  // initialisation of mainFrame components, event handler methods, etc.

  main {
    // this is commented as "the entry point of the program"
    // some setup stuff, probably important
    // instance of mainFrame is created here
    // init method is called here
  }
}

我的问题是:

  1. 第二个窗口应该在哪里创建和初始化?可以在这个.java文件里完成,还是需要单独的.java + .form文件组合?
  2. 如果可以在mainFrame文件里完成,那具体应该在哪里声明、设置、创建、初始化它?它需要自己的init方法吗?原来的init方法里有多少内容需要复制到新的对应方法中?
  3. 如果它需要单独的.java + .form文件组合,是不是要把mainFrame的整个.java文件复制过去,然后针对全屏模式修改?有多少内容需要复制(如果有的话)?

如果有人能帮忙,我很乐意分享源码仓库的链接。mainFrame的.java文件太长了,没法全部粘贴在这里。

备注:内容来源于stack exchange,提问作者Willicious

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 10:34:33