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

300

Figure 9.1 Displaying a frame.

301

Creating a Component

Adding Components to a Container

Second Program

Listing 9.2 - The Full Text of ButtonFrame.java

Listing 9.2 - The Full Text of ButtonFrame.java

305

Figure 9.2 The Button Frame application.

306

Working with Components

Image Icons

Third Program

Listing 9.3 - The Full Text of IconFrame.java

Figure 9.3 goes here

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

Labels

Text Fields

Text Areas

Fourth Program

Listing 9.4 - The Full Text of Authenticator.java

Figure 9.5 goes here

Scrolling Panes

Check Boxes and Radio Buttons

Fifth Program

Listing 9.5 - The Full Text of FormatFrame.java

Explanation

Figure 9.6 goes here

Combo Boxes

Sixth Program

Listing 9.6 - The Full Text of FormatFrame2.java

Explanation

Figure 9.7 goes here

Lists

Seventh Program

Listing 9.7 - The Full Text of Subscriptions.java

Explanation

Figure 9.8 goes here

The Java Class Library

Figure 9.9 goes here



Summary



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

Answers

  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.


Exercise