19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

468 Chapter 12 GUI Basics<br />

Component Container JComponent<br />

AbstractBut<strong>to</strong>n<br />

JLabel<br />

JTextComponent<br />

JComboBox<br />

JBut<strong>to</strong>n<br />

JCheckBox<br />

JToggleBut<strong>to</strong>n<br />

JRadioBut<strong>to</strong>n<br />

JTextArea<br />

JTextField JPasswordField<br />

JList<br />

JScrollBar<br />

JSlider<br />

FIGURE 12.14<br />

These Swing GUI <strong>com</strong>ponents are frequently used <strong>to</strong> create user interfaces.<br />

naming convention for<br />

<strong>com</strong>ponents<br />

AbstractBut<strong>to</strong>n<br />

Note<br />

Throughout this book, the prefixes jbt, jchk, jrb, jlbl, jtf, jpf, jta, jcbo,<br />

jlst, jscb, and jsld are used <strong>to</strong> name reference variables for JBut<strong>to</strong>n,<br />

JCheckBox, JRadioBut<strong>to</strong>n, JLabel, JTextField, JPasswordField,<br />

JTextArea, JComboBox, JList, JScrollBar, and JSlider.<br />

A but<strong>to</strong>n is a <strong>com</strong>ponent that triggers an action when clicked. Swing provides regular but<strong>to</strong>ns,<br />

<strong>to</strong>ggle but<strong>to</strong>ns, check box but<strong>to</strong>ns, and radio but<strong>to</strong>ns. The <strong>com</strong>mon features of these but<strong>to</strong>ns<br />

are defined in javax.swing.AbstractBut<strong>to</strong>n, as shown in Figure 12.15.<br />

javax.swing.JComponent<br />

javax.swing.AbstractBut<strong>to</strong>n<br />

-actionCommand: String<br />

-text: String<br />

-icon: javax.swing.Icon<br />

-pressedIcon: javax.swing.Icon<br />

-rolloverIcon: javax.swing.Icon<br />

-mnemonic: int<br />

-horizontalAlignment: int<br />

-horizontalTextPosition: int<br />

-verticalAlignment: int<br />

-verticalTextPosition: int<br />

-borderPainted: boolean<br />

-iconTextGap: int<br />

-selected: boolean<br />

The get and set methods for these data fields are provided<br />

in the class, but omitted in the UML diagram for brevity.<br />

The action <strong>com</strong>mand of this but<strong>to</strong>n.<br />

The but<strong>to</strong>n’s text (i.e., the text label on the but<strong>to</strong>n).<br />

The but<strong>to</strong>n’s default icon. This icon is also used as the “pressed” and<br />

“disabled” icon if there is no pressed icon set explicitly.<br />

The pressed icon (displayed when the but<strong>to</strong>n is pressed).<br />

The rollover icon (displayed when the mouse is over the but<strong>to</strong>n).<br />

The mnemonic key value of this but<strong>to</strong>n. You can select the but<strong>to</strong>n by<br />

pressing the ALT key and the mnemonic key at the same time.<br />

The horizontal alignment of the icon and text (default: CENTER).<br />

The horizontal text position relative <strong>to</strong> the icon (default: RIGHT).<br />

The vertical alignment of the icon and text (default: CENTER).<br />

The vertical text position relative <strong>to</strong> the icon (default: CENTER).<br />

Indicates whether the border of the but<strong>to</strong>n is painted. By default, a regular<br />

but<strong>to</strong>n’s border is painted, but the borders for a check box and a radio<br />

but<strong>to</strong>n are not painted.<br />

The gap between the text and the icon on the but<strong>to</strong>n.<br />

The state of the but<strong>to</strong>n. True if the check box or radio but<strong>to</strong>n is selected,<br />

false if not.<br />

FIGURE 12.15<br />

AbstractBut<strong>to</strong>n defines <strong>com</strong>mon features of different types of but<strong>to</strong>ns.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!