Radio Buttons

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

One.

Radio Buttons

CarRadio

Car radios and some table radios have buttons for selecting radio stations. Only one station is selected at a time. When one button is pushed in the previous one pops out. The Swing class JRadioButton works the same way. Radio buttons must be members of a ButtonGroup. Only one button of a button group is selected at any time.

Here is a constructor for JRadioButton: (There are other constructors that may be useful, but not mentioned here.) (See the Java documentation.)
JRadioButton( String text, boolean selected )

text is the string that is placed next to the button. If selected is true then this button starts out selected. Only one button of a button group may start out as selected. JRadioButton is a child class of JAbstractButton. Radio buttons and JButtons have many methods in common.

QUESTION 2:

(Thought Question: ) Does clicking on a radio button generate an action event?