Java Reference
In-Depth Information
covering the Basics of guis in Java
Java has been around for a while, so there are quite a number of GUI frameworks to choose from
when you decide to start building your own user interfaces, both in the form of built‐in as well as
third‐party libraries.
The reasons behind this are mostly historical, but are also influenced quite a bit by functional deci-
sions. Some frameworks, for instance, will opt to keep as close as possible to the native look and
feel of the operating system Java is running on, whereas others will try to go for a fancy, modern,
or eccentric look. Some will focus on robustness or simplicity, whereas others will utilize advanced,
performance‐oriented functionalities such as hardware acceleration.
As a beginner's chapter on building GUIs with Java, things will be kept simple, using only built‐in func-
tionality without relying on third‐party libraries or features that are too hard or complex to use. You'll
note that unless you're building graphic‐intensive programs, these components will serve just fine.
highlighting the Built‐in gui libraries
Before getting your feet wet with building your first GUI application, you need to get acquainted
with some of the basics. You can start off with a short introduction, highlighting a bit more the
architecture and history of Java's built‐in GUI libraries.
abstract Window toolkit (aWt)
Back when Java was first released in 1995, Sun Microsystems provided a built‐in library, called the
Abstract Window Toolkit (AWT), to provide a standard widget toolkit (a widget is a typical GUI
term used for a specific GUI component, such as a button or a check box) in the form of a thin layer
above the native, underlying user interface, defined by the operating system. This meant that creat-
ing a button with AWT would call the routines of the underlying operating system as straightfor-
wardly as possible to display the actual button, meaning that widgets created with AWT would look
different depending on the actual operating system the Java program was running on; For example,
OSX buttons look different than Windows buttons.
Although AWT is closely coupled to the underlying operating system (its components are called
“heavyweight components” for that reason), the library itself is still enormous. It consists of no less
than 12 packages, containing the collection of GUI widgets, classes to deal with GUI events (you
will learn about events in the context of GUIs later), classes dealing with layout managers, interfaces
to deal with input devices such as the mouse and keyboard, and even classes to handle the clipboard
(copying and pasting) and drag‐and‐drop functionality.
Swing
Swing was originally developed to offer a more advanced set of GUI widgets compared to AWT.
One goal was to offer a set of GUI components that would emulate the look and feel of the host
operating system (as this was what users were familiar with) by default, but would also support a
pluggable look‐and‐feel system that would allow applications to have a separate visual style.
In addition, Swing aimed to offer more components when compared to AWT, such as tabbed pan-
els, lists, and scroll panes. Finally, unlike AWT widgets, Swing components are not implemented
by relying on operating system-specific code. Instead, they are written entirely in Java and thus
 
Search WWH ::




Custom Search