Java Reference
In-Depth Information
You should also be comfortable with creating buttons and grouping radio buttons and checkboxes to ensure
that only one can be selected at any given time.
In the next chapter you move on to look at events — that is, how you associate program actions with
menu items and components within a window.
EXERCISES
You can download the source code for the examples in the topic and the solutions to the following exer-
cises from www.wrox.com .
1. Create an application with a square window in the center of the screen that is half the height of the
screen by deriving your own window class from JFrame .
2. Add six buttons to the application in the previous example in a vertical column on the left side of
the application window.
3. Add a menu bar containing the items File, Edit, Window, and Help.
4. Add a drop-down menu for Edit containing two groups of items of your own choice with a separator
between them.
5. Add another item to the Edit drop-down menu, which itself has a drop-down menu, and provide
accelerators for the items in the menu.
6. Here's an exercise to tickle the brain cells — use a SpringLayout to obtain the button arrangement
shown in Figure 17-40 in an application window.
FIGURE 17-40
• WHAT YOU LEARNED IN THIS CHAPTER
TOPIC CONCEPT
GUI ClassesThe package javax.swing provides classes for creating a graphical user interface.
ComponentsA component is an object that is used to form part of the GUI for a program. All components have the
class Component as a superclass.
Containers A container is a component that can contain other components. A container object is created with a class
that is a subclass of Container . The classes JPanel , JApplet , JWindow , JFrame , and JDialog are con-
tainers.
 
 
Search WWH ::




Custom Search