Swing, the new user interface for Java, has a little something in common
with its namesake dance. Even if you hate Big Bad Voodoo Daddy, even if you
find checkered loafers absurd, there has to be a part of you that says, "That's
cool," the first time you see a woman get tossed into a 360 and then keep dancing.
Though there may be very good reasons for staying away
from Java, this new interface has a undeniable coolness factor. Using
Swing, which will ship with the 1.2 release of the Java Development Kit,
a developer has the option of creating attractive applications that look
and behave identically on all platforms. Every button,
list box, and window will be exactly the same no matter what OS they're on.
There will be no need to worry about, for instance, the difference between
a PC's proportional scroll bar and a Mac's non-proportional one.
Of course, you can still create applications that appear to be native to Mac,
Windows, or Unix. In fact, Swing
even allows developers to create controls from scratch.
This is possible because of a nifty change in Java's architecture. Prior
to Swing, all Java applets had to go through the cumbersome process of
determining the user's operating system, then accessing the system's native
code. Java would then negotiate with the native code to create windows, buttons, and
all the other familiar objects. User events - like clicks and mouseovers - had
to traverse the other way: from the native code, through a translator, and
finally to Java itself. A window created by Java accessed the same native
code as C++ or Visual Basic, but it did this in a much more circuitous
way, leaving a lot of room for error.
Swing uses very little native code. After a primary window is created
with native code, all objects within that window are essentially painted by
components completely controlled by Java. It accomplishes this by using a
modified model-view-controller architecture. At it's most basic
level, the model aspect handles all of the application's data, the view
takes care of output to the screen, and the controller works with the user
events. The three portions continually interact to create a functioning
application that uses a bare minimum of native code. Of course, this is a
quick and dirty explanation. Check out the white
paper on Swing's architecture if you're really interested - or a
masochist.
next page»