Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Swing
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.
Posted 9-Sep-12 8:44am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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();
  }
}
 
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.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Mathew Soji 274
1 BillWoodruff 270
2 Afzaal Ahmad Zeeshan 244
3 Sergey Alexandrovich Kryukov 240
4 Raul Iloc 160
0 OriginalGriff 6,219
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,103
3 Manas Bhardwaj 4,549
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 10 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100