Swing - The Classic Java UI


Swing ”The "Classic" Java UI

Swing is the standard Java UI included with the Java SDK. It has been part of Java since the earliest days, when it superseded the older AWT (Abstract Window Toolkit). The AWT was designed to use "heavyweight" components ”this term indicated that the AWT routines directly called OS-specific graphical routines. For example, on Windows, the AWT directly interfaced with the Windows APIs. Various problems arose from this, the top two being the following:

  1. Not all operating systems supported the same low-level functions. This meant that code had to be written to support certain functions or, in severe cases, that certain functionality had to be left out of a platform implementation.

  2. OS APIs tended to change from version to version. This was particularly true back in the late 1990s, when it seemed that Microsoft was releasing a new operating system every six months. The APIs were wildly inconsistent from one version of the OS to another, and this meant rewriting the AWT interfaces.

With those two objections in mind, the decision was made to switch to a completely "lightweight" implementation of the GUI, and thus Swing was born. I'm not sure of the exact details, but the idea is that only a couple of basic features of the operating system are used, such as creating a window, capturing an event, or drawing simple graphics. Everything else is written in 100% Java. So, when you decide to create a button on the screen, every edge and every line is drawn by the Swing toolkit. If you take the time to look at the buttons on today's GUIs, you'll see that this is actually a pretty complex feat, since the buttons tend to be "three-dimensional," with lighter shading to the left and above and darker shading to the right and below. Not only that, the buttons actually "depress" when you click them. This is quite a bit of work, and with Swing this work is done in Java rather than by the operating system.

This leads to one of the biggest detractions from Swing: its performance. Swing is noticeably slower, especially on smaller machines. While optimizing compilers can help to reduce some of that overhead, Swing to date just hasn't been able to provide as crisp a user interface as native graphics, and this more than anything has slowed its acceptance.

There are many great benefits to Swing. Swing was designed from the ground up to provide complete accessibility for alternate user interface devices, thus allowing applications to be easily modified to support speech- or sight-challenged users or other users with alternate input devices. Swing can also easily change its "look and feel" from one style to another with a single API call, allowing it to switch from mimicking Windows to mimicking the Mac user interface. However, for several reasons, not the least of which is the constant changes in the various operating systems, Swing, while often coming close to the actual look and feel of a native application, never quite accomplishes it.




Eclipse
Eclipse: Step by Step (Step-by-Step series)
ISBN: 1583470441
EAN: 2147483647
Year: 2003
Pages: 90
Authors: Joe Pluta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net