Fundamentals of the AWT
The Abstract Window Toolkit can be used by Java applications and applets. But I recommend that:
Applets:
- not use frames
- not use menus
If you do use menus/frames(i.e for a pop-up menu), then you must live with the "untrusted window" message.
More importantly, Frames/Dialogs can to ill-behaving and not close if you do not handle the Event.WINDOW_DESTROY message.
But.. we will start with applications first of all, because of fewer restriction. Although
I will try not to provide information too specific to stand-alone applications. The first few sections
are not particularly useful for applet writers, but later sections rely on concepts learnt early on.
Structure of the AWT
The current release of the AWT has this type of of structure:
- Containers used to contain Components, which are your basic UI controls.
- Layouts vs. fixed positioning of Components.
- Lowest common denominator approach to keyboard, mouse and event handling.
- High level of abstraction from the underlying GUIs. i.e no Non-clients areas, X calls, hWnds, etc.
- The look-and-feel of the application is dependant on the underlying GUIs rather than "one-size-its all".
- Not very device-independant(i.e can not assume a dialog will be the 'same size' on every computer) and the lack of ability to 'draw to the printer' rather than the screen.
- Lacks a resource format. Thus the ability to separate code from the interface, via designing the interface
with a GUI builder and 'adding' event handling code. Albeit I've heard a Windows RC to AWT in development
- Class hierarchy is fairly shallow, but the AWT is not an application framework either. So it's missing
a doc/view architecture.
Since the JDK 1.0 has been released. Applets and Application tend to have similar functionality. Yet there
are times when an applet can not be a stand-alone app, but that case will soon disappear as shown between Beta 1 to the official "One-point Oh" release. Applets and Applications may one day have the same functionality.
Bugs in the AWT(JDK 1.0)
- Dialogs cannot be Modal
- clipRect is bugged
- Mouse events are quirky(especially mouseDown)
Steps for stand-alone applications using the AWT:
- Interface:
- Create your Frame
- Do initialization of fonts, colors, layouts and other resources
- Create your menus and menubars
- Create your controls, dialogs, windows, etc.
- Implementation
- Add event handlers
- Add functionality(i.e threading, networking, etc)
- Add error-handling(i.e exceptions)
Since this is an AWT Tutorial we will focus on the interface part first and come back to
show how to integrate threading and networking into your applications(or applets).
[Next]
[Prev]
[Home]
Nelson Yu
nelson@cs.ualberta.ca
Last modified: Feb 21 1996