I am working on a Java Swing desktop application project. The application has about 15 GUI pages. I can use Layered Panes and Tabbed Panes to put all the GUI components in one class. But that class will be huge. It would be idea if I can divide the project into several smaller sub-projects and let each have one or a few GUI pages. I can work on each sub-project individually and integrate them back into one application when all sub-projects are finished. My question is that how I can integrate all GUI pages from different classes so I can navigate back and force among different pages on button clicks? Since the sub-projects contain GUI pages each needs to have a JFrame. How I can switch back and force between JFrame 1 to JFrame 2 and make one visible and the other invisible? This question shows how to create new JFrames. But did not show how switch back and forth among the JFrames.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Not necessarily. The GUI could be quite simple, and could have a method that would allow other classes to add a page, say something called
registerPage(...)
:Then give the class methods to allow one to go to the next or previous page or to a random page. For example a class as small as this could work:
All this class really does is act as a repository for your "pages" and has the logic to allow flipping through pages either contiguously or randomly, and not much else, but that's all it really needs to do, and by limiting it so, we limit the class's size. If other functionality is needed, create other classes for these
... such as our Action classes including the PrevAction class:
and NextAction.java
And you would need to have a main method of course:
But it wouldn't be a huge class by any means, and you wouldn't have to worry about flipping multiple JFrames at the user.
Your idea of a centralised controller isn't a bad one.
Personally, my first thoughts would be to try a group these separate pages into domain groups (or groups of responsibility). This would give me my first level of control. I'd decide how I would like these domains to be used by the user.
Once you have that working, you can move to the next level, which groups work with each other (if any) & how would you like the user to interact with these
And so forth.
I agree with HovercraftFullOfEels, you don't want to throw lots of windows at users, this just frustrates them, you also don't want them to have to flick between related pages, where the information on one is useful on another.
You might find that you end up with a combination of both. That is, you might need to provide the user with the flexibility to open some pages in frames. This would allow them the ability to decide what information they always need & what information they can flip through.
IMHO
You have a couple of options:
You can get some more information on these methods and how they should be called here: http://docs.oracle.com/javase/6/docs/api/javax/swing/JFrame.html
Hope this helps!