Header javaperspective.com
JavaPerspective.com  >   Intermediate Tutorials  >   5. Graphical User Interfaces

5. Graphical User Interfaces
Last updated: 1 February 2013.

This chapter will show you how to build graphical user interfaces in Java with the Swing library.

A graphical user interface (GUI) is a frame containing interactive components like buttons, editable text fields, check boxes, combo boxes and so on. This chapter will give you tips in building graphical user interfaces in Java with a library called Swing that is included in the JDK.

In fact, the JDK provides two libraries for building GUIs: AWT (Abstract Windowing Toolkit) and Swing. AWT is the Java platform's first library for GUI development. Swing was introduced later as a replacement to AWT.

The difference between AWT and Swing is that AWT is based on heavyweight native system components whereas Swing implements lightweight Java portable components. Consequently, the two libraries differ in the following areas:

In the light of the above, Swing seems to be a better choice than AWT for building GUIs, which is the reason why these tutorials only discuss GUI development with Swing. Besides, because AWT code is very similar to Swing code, if you can do Swing GUIs then you can pick up AWT with relative ease.

In fact, although Swing has a completely different approach to creating components, it is actually built on top of AWT. Consequently, when developing GUIs with Swing, you will probably have to import from AWT as well (fonts, colors, layouts, ... belong to AWT).

In the Java API, the AWT classes are in the package java.awt and the Swing classes are in the package javax.swing. The names of Swing components start with the letter J (JButton, JPanel, JFrame, ...) whereas AWT components do not (Button, Panel, Frame, ...).

As I said earlier, the tutorials of this chapter will look at GUI development with Swing. Nevertheless, if you still want to use AWT to build GUIs, note that it is not recommended to mix up AWT components with Swing components. Even if a program mixing up AWT and Swing components generally compiles, the result may display incorrectly.

The tutorials of this chapter are logically sequenced: tutorials 5.1 to 5.6 (included) discuss the basics I believe you need to know before being able to efficiently build GUIs with Swing. Then the tutorial 5.7 and the following will show you how to use a wide range of common Swing components.

This chapter is the last one in the intermediate section. More advanced Swing features will be discussed at the beginning of the advanced section.




You are here :  JavaPerspective.com  >   Intermediate Tutorials  >   5. Graphical User Interfaces
Next tutorial :  JavaPerspective.com  >   Intermediate Tutorials  >   5. Graphical User Interfaces  >   5.1. Swing class hierarchy

Copyright © 2013. JavaPerspective.com. All rights reserved.  ( Terms | Contact | About ) 
Java is a trademark of Oracle Corporation
Image 1 Image 2 Image 3 Image 4 Image 5 Image 6 Image 7