I have spent the last several hours scouring the internet looking for examples and ideas on how to write a medium sized GUI in java. I know a little about swing but that is all. I don't know of any other way to develop a GUI in Java besides swing. If you know of a different way that would be good too. I also want to hand-write the GUI myself to allow for easier integration with our game and future refactoring.
We have written the entire business logic to a Tic Tac Toe game that has several features. The gui needs to have several windows which can be navigated using simple buttons on the interface. A very crude and water-downed version of what I am looking to do can be seen below:
The Heart of my question is this:
How do I architect the GUI using Swing and what general design is used?
and some follow-up questions:
Is there a class for every window? Do I just use setvisible
to make my windows appear and disappear after the buttons are pressed?
`re there any examples you all know of (github repos would be excellent! happy forking!) that could show me a good gui architecture/design?
Swing in Java is a lightweight GUI toolkit which has a wide variety of widgets for building optimized window based applications. It is a part of the JFC( Java Foundation Classes). It is build on top of the AWT API and entirely written in java. It is platform independent unlike AWT and has lightweight components.
Swing architecture is rooted in the model-view-controller ( MVC) design that dates back to SmallTalk . MVC architecture calls for a visual application to be broken up into three separate parts: A model that represents the data for the application. The view that is the visual representation of that data.
The Swing toolkit uses a modified MVC design pattern. It has a single UI object for both the view and the controller. This modified MVC is sometimes called a separable model architecture. In the Swing toolkit, every component has its model, even the basic ones like buttons.
I think you can create multiple JPanels (or their extensions) place them in one container with CardLayout and switch cards when necessary.
Also consider the Model–View–Controller pattern, discussed here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With