Abbey Workshop | ||||||||||
This is a short example of how to create a basic Swing gui application in Java. (The tip consists mainly of the code shown below.) This example demonstrates a border layout and uses buttons inside of panels to fill in the layout. To build an application from this, simply replace the buttons with gui components of your choosing.
You will notice a method is used to create and launch a frame. We do not extend JFrame. In theory, by not doing this, it allows us to inherit from another object thus giving us more flexibility. Well, in theory anyway.
I initialize components as attributes of the class. Since Swing components used to build the UI do not change, this seems like a good place to define them. The constructor is then used to assemble the components you have defined.
Download source for: BasicGui.java
Copyright © Abbey Workshop 2006