Write a JavaFX application that allows the user to display an image out of three based on a radio button choice. Make sure to use SetImage somewhere in the program
Solution:
Processing Events for Radio Buttons:
The application perform an action when one of the radio buttons in the group is selected.
Example:
ImageView image = new ImageView();
rb1.setUserData("Home")
rb2.setUserData("Calender");
rb3.setUserData("Contacts");
final ToggleGroup group = new ToggleGroup();
group.selectedToggleProperty().addListner(new ChangeListner<Toggle>(){
public void changed (ObservableValue<? extends Toggle> ov,
Toggle old_toggle, Toggle new_toggle) {
if (group.getSelectedToggle () != null) {
final Image image = new Image (
getClass ().getResourceAsStream(
group.getSelectedToggle ().getUserData ().toString () + ".jpg"
)
);
icon.setImage(image);
}
}
});
Get Answers For Free
Most questions answered within 1 hours.