Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GUI Architecture and Design in Java (Swing)

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:

Main MenuNetwork Box

Game Board

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?

like image 437
Matthew Kemnetz Avatar asked Nov 30 '11 06:11

Matthew Kemnetz


People also ask

What is Swing GUI in Java?

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.

What is the architectural structure of Swing?

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.

What design pattern does Java Swing use?

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.


2 Answers

I think you can create multiple JPanels (or their extensions) place them in one container with CardLayout and switch cards when necessary.

like image 73
StanislavL Avatar answered Sep 21 '22 00:09

StanislavL


Also consider the Model–View–Controller pattern, discussed here.

like image 32
trashgod Avatar answered Sep 21 '22 00:09

trashgod