Blakes 21 Days Chapter 09 Document

Day 9, Working with Swing

Creating an Application

Creating an Interface

Developing a Framework

Listing 9.1

Listing 9.1 - The full Text


Figure 9.1 Displaying a frame.


Creating a Component

Adding Components to a Container

Second Program

Listing 9.2 - The Full Text of

Listing 9.2 - The Full Text of


Figure 9.2 The Button Frame application.


Working with Components

Image Icons

Third Program

Listing 9.3 - The Full Text of

Figure 9.3 goes here

Figure 9.4 goes here (Dragging files into the NetBeans Files pane.)


Text Fields

Text Areas

Fourth Program

Listing 9.4 - The Full Text of

Figure 9.5 goes here

Scrolling Panes

Check Boxes and Radio Buttons

Fifth Program

Listing 9.5 - The Full Text of


Figure 9.6 goes here

Combo Boxes

Sixth Program

Listing 9.6 - The Full Text of


Figure 9.7 goes here


Seventh Program

Listing 9.7 - The Full Text of


Figure 9.8 goes here

The Java Class Library

Figure 9.9 goes here


Q & A

Quiz - Questions

  1. Which of the following user interface components is not a container ?
    1. JScrollPane
    2. JTextArea
    3. JPanel
  2. Which componenet can be placed into a Scroll pane ?
    1. JTextArea
    2. JTextField
    3. Any component
  3. If you use setSize()on an application's main frame, where will it appear on your desktop ?
    1. At the center of the desktop
    2. at the same spot the last application appeared
    3. At the upper-left corner of the desktop


  1. B. A JTextArea requires a container to support scrolling, but it is not a container itself.
  2. C. Any component can be added to a Scroll pane, but most are unlikely to need scrolling.
  3. C. Tis is a trick question. Calling setSize() has nothing to do with a window's position on the desktop. You must call setBounds() rather than setSize() to choose where a frame will appear.

Certification Practice

  1. What statement needs to replace // answer goes here to make the application function properly ?
    1. setSize(300, 200);
    2. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    3. Display ds = new Display();
    4. No statement needed.