Checkboxes and Radio Buttons
A checkbox is a labeled toggle switch. Each time the user clicks
it, its state toggles between checked and unchecked. Swing
implements the checkbox as a special kind of button. Radio
buttons are similar to checkboxes, but they are usually arranged
in groups. Click on one radio button in the group, and the others
automatically turn off. They are named for the preset buttons on
old car radios.
Checkboxes and radio buttons are represented by instances of
JCheckBox and JRadioButton,
respectively. Radio buttons can be tethered together using an
instance of another class called ButtonGroup. By now you're
probably well into the swing of things (no pun intended) and
could easily master these classes on your own. We'll use an
example to illustrate a different way of dealing with the state
of components and to show off a few more things about containers.
A JCheckBox sends ItemEvents when it's
pushed. Since a checkbox is a kind of button, it also fires
ActionEvents when it becomes checked. For something
like a checkbox, we might want to be lazy and check on the state
of the buttons only at some later time, such as when the user
commits an action. It's like filling out a form; you can change
your choices until you submit the form.
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|