Java Reference
In-Depth Information
Q
How do I center a window on screen?
A
To center a window on screen, get the window dimensions from the
java.awt.Toolkit.getDefaultToolkit().getScreenSize()
method. Use the returned
Dimension
to calculate the vertical and horizontal center of the screen while taking into
account the dimensions of the window you want to center. Finally, place the window at
that location, as in the following code snippet used for centering our
connectionDialog
object:
// Center on screen
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (int) ((d.getWidth() - connectionDialog.getWidth())/ 2);
int y = (int) ((d.getHeight() - connectionDialog.getHeight())/ 2);
dialog.setLocation(x, y);
Q
How do I create keystroke mnemonics for my GUI components?
A
You can add keystroke mnemonics to virtually any component via the
setMnemonic(int
keyValue)
method. Lists of predefined key values are located in the
KeyEvent
class.
Q
Can I use the Macintosh look and feel on a Windows operating system, or vice versa?
A
Sun provides several cross-platform interface look and feel packages. Metal and Motif
were the only guaranteed look-and-feel libraries prior to JDK 1.5. With the release of
JDK 1.5 Sun has included Ocean (a custom Metal theme), and Synth (a skinnable look
and feel). Most other libraries are operating system-specific. Although it might be
technically possible to use the Windows look and feel on a Mac, or vice versa, it is usu-
ally not legal to distribute an application that uses one operating system's look and feel
on another platform.
Part of the power of Swing is its capability to be extended and make custom look-and-
feel libraries. Some custom libraries are available that are cross-platform, but they are
not part of the standard Java distributions and are difficult to rely on for interface
design.
Q
I found a look and feel on the Web that I prefer to any of Sun's look and feels. Can I use
it instead?
A
Check your instructions carefully—most instructions state that
all
code submitted
must be your own. If you use a look and feel that you did not write and that is not part
of the JDK, then you will be violating this rule.
Q
Where can I find out more about Java look-and-feel guidelines?
A
You can find extensive information pertaining to Java interface design and standard
practices at
http://java.sun.com/products/jlf/
.
Q
Where can I find out more information on interface design and usability testing?
A
The following URLs are great places to begin research into usability engineering and
testing:
http://www.useit.com
http://www.asktog.com