Java Reference
In-Depth Information
Finally, a gentle reminder: the AGUI, like Swing, is
not
thread-safe. Swing
components should be accessed by only one thread at a time; usually, this is the
event-dispatching thread. If you're writing a multithreaded application that needs to
work with the AGUI interface, you should ensure that all AGUI updates occur on the
event-dispatching thread. You can do this using the
javax.swing.SwingUtilities
class;
it provides the static methods
invokeLater
and
invokeAndWait
, which take a
Runnable
to perform on the event-dispatching thread after the window system handles all
pending events. Use the
invokeLater
method to queue an action to perform on the
event-handling thread; this is preferable to
invokeAndWait
, which blocks until the
window system has completed your task.
Understanding Restrictions on Top-Level Windows
The PBP permits devices to disallow multiple top-level windows. When the AGUI is com-
bined with a device that does not permit multiple top-level windows, the AGUI suffers
from the same limitation: only a single
JFrame
is permitted on a single graphics device.
Attempts to construct a second
JFrame
fail, and the runtime throws the
java.lang.
UnsupportedOperationException
. This means that, for maximum portability between
AGUI-enabled devices, your user interface should reside entirely in one window.
This has ramifications for other containers as well. For example, the
JOptionPane
may
only use lightweight containers to display dialogs, and it may not be possible to create a
top-level dialog by creating a
JOptionPane
with a
null
value for its parent component.
Similarly, pop-up menus should be rooted in a specific container; you can't create a
JPopupMenu
with a
null
invoker. Moreover, like the
JOptionPane
, the
JPopupMenu
may only
use lightweight components in its composition.
Using the AGUI's Added Input Support
Many consumer electronics devices do not have a traditional keyboard; in fact, many
consumer electronics devices have
different
input devices from each other altogether.
This poses a challenge for any generic window toolkit, which must somehow abstract the
differences between disparate devices.
The AGUI borrows the notion of input constraints that limit what a user can enter
from MIDP 2.0 by passing the
INPUT_CONSTRAINT
client property to a
JTextComponent
via the
putClientProperty
method. Table 10-2 shows the input constraints that an implementa-
tion of the AGUI may support.