如何在Java Swing应用程序中导航黑白多帧 [英] how to navigate b/w multiple frame in java swing application

查看:107
本文介绍了如何在Java Swing应用程序中导航黑白多帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


先生/女士,我在Java环境中是新手.我必须开发一个基于Java swing的项目.我已经使用JFrame制作了一个表单,但是根据主框架窗口的要求,打开时会有一些选项卡应该打开新的框架窗口.我还没有从主框架window.plz中打开多个框架窗口的想法.帮我先谢谢.

Hi
Sir/Mam i am new in java environment. i have to develop a project based on java swing. i have made a single form using JFrame.but as per the requirement in main frame window there is some tab on opening there should be open new frame window.i have not gotten the idea how to open multiple frame window from main frame window.plz help me someone thanks in advance.

推荐答案

您需要一种体系结构.

您的应用程序不需要具有可见的JFrame-因此,您的应用程序也可以具有多个JFrame.

您的主类-应用程序的起点-需要触发没有 GUI的基本应用程序.

该基本应用程序定义了生命周期.当它关闭时,应用程序完成.
基本应用程序有一项主要任务:保存数据,以便不同的JFrames可以访问它:

You need an architecture.

You application does not need to have a visible JFrame - therefor your application can also have multiple JFrames.

Your Main-class - starting point for the application - needs to trigger a basic application without GUI.

That basic application defines the lifecycle. When it is closed down the application is finished.
The basic application has one major task: it''s holding the data, so that different JFrames can access it:

public class Main {

  private static Facade oFacade = new Facade();
	
  public static void main(String[] args) {
    startFacade();
    startGUI();
  }

  private static void startGUI() {
    new GUI(oFacade);
  }

  private static void startFacade() {
    oFacade.init();
  }
}



外观的概念是Java开发中的常见模式(有关外观模式的维基百科 [



The concept of a facade is a common pattern in Java development (Wikipedia on facade pattern[^]

public class Facade {

  public void init() {
    // holding data 
  }
}





public class GUI{
  public GUI(Facade oFacade) {
    // controls JFrames
  }

  // needs to trigger end of lifecycle as the Main-class will not figure it otherwise and life happily forever and on.
}



基本上,这也是应用程序框架为您完成的工作-更加丰富,更加复杂.



That is basically also what an application framework does for you - much richer, much more complex.


这篇关于如何在Java Swing应用程序中导航黑白多帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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