Java Reference
In-Depth Information
A large number of users of classes that implement JRootPane do not need to use the vari-
ous panes that exist—they only need to add content to the content pane. So in JDK 5 Sun has
rewritten the add methods of these classes so that they perform in the way most users would
expect. This allows us to rewrite the previous code as shown here:
JFrame theFrame = new JFrame();
theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
theFrame.add(new JButton("Exit"));
theFrame.pack();
theFrame.setVisible(true);
This reduces confusion as to when we should be dealing with the frame itself or the panel,
and makes the code a little more readable.
Summary
A sound interface design will bridge the gap between the user and the system. By using solid
design patterns, such as the Model-View-Controller (MVC) architectural paradigm, you can
ensure that changes to the data display have minimal impact on the rest of the system. On a
superficial level, the end user will most likely judge the quality of an application based on
the functionally of its interface, so it is important to plan and design a quality front-end to a
system.
In this chapter we introduced GUI design, and provided some examples of how you can
combine various layout managers and components to achieve your desired design. It is
important to realize that there is no “one right way” to develop a GUI, so you can use the tech-
niques introduced here to develop GUIs that you believe will be usable for your instructions.
FAQs
Q The instructions state that I may only use Swing components, but none of the layout
managers are part of the javax.swing package—will this cause me to fail?
A You will be fine using any of the layout managers. However, you must not use an AWT
component where there is a Swing replacement. For example you should not use a
Button since there is a Swing replacement: the JButton .
Q Does Swing replace AWT?
A Swing is not a replacement for AWT. Swing is built on the patterns and groundwork
set forth in AWT. Both Swing and AWT components can be mixed and matched in any
interface, to an extent (however, only Swing components may be used in the Sun
assignment).
Swing does offer some large improvements over AWT both in performance and func-
tionality. Therefore, Sun now emphasizes Swing over AWT. As a result, Swing is a
required part of the SCJD exam.
Search WWH ::




Custom Search