Recreate an interface using JavaFX and any of its associated

Recreate an interface using JavaFX and any of its associated controls. Make a car radio with a VBox containing two HBoxes with one HBox containing power, a display screen to show stations and tuning buttons. Another HBox containing 5 buttons for preset stations. It must have 1 bound property (whatever that means if you can explain it) and node property customization. The program should display the buttons to resemble a car radio. Although the buttons need to look like a car radio and sized accordingly they do not need to be functional. Image/Image view are optional but useful.

Solution

PLEASE FIND BELOW THE JAVA PROGRAM TO CREATE A CAR RADIO BUTTON :

package carRadiosample;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.*;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.geometry.Insets;

public class carRadioSample extends Application {

final ImageView icon = new ImageView();
  
public static void main(String[] argnts) {
launch(argnts);
}

@Override
public void start(Stage stage) {
Scene scene = new Scene(new Group());
stage.setTitle(\"Car Radio Sample\");
stage.setWidth(230);
stage.setHeight(140);

final ToggleGroup group = new ToggleGroup();

RadioButton rb1 = new RadioButton(\"Station1\");
rb1.setToggleGroup(group);
rb1.setUserData(\"Station1\");

RadioButton rb2 = new RadioButton(\"Station2\");
rb2.setToggleGroup(group);
rb2.setUserData(\"Station2\");

RadioButton rb3 = new RadioButton(\"Station3\");
rb3.setToggleGroup(group);
rb3.setUserData(\"Station3\");

   RadioButton rb4 = new RadioButton(\"Station4\");
rb4.setToggleGroup(group);
rb4.setUserData(\"Station4\");

   RadioButton rb5 = new RadioButton(\"Station5\");
rb5.setToggleGroup(group);
rb5.setUserData(\"Station5\");


group.selectedToggleProperty().addListener(new ChangeListener<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);
}
}
});

HBox hbox = new HBox();
VBox vbox = new VBox();

vbox.getChildren().add(rb1);
vbox.getChildren().add(rb2);
vbox.getChildren().add(rb3);
   vbox.getChildren().add(rb4);
   vbox.getChildren().add(rb5);
vbox.setSpacing(20);

hbox.getChildren().add(vbox);
hbox.getChildren().add(icon);
hbox.setSpacing(60);
hbox.setPadding(new Insets(20, 10, 10, 20));

((Group) scene.getRoot()).getChildren().add(hbox);
stage.setScene(scene);
stage.show();
}
}

Recreate an interface using JavaFX and any of its associated controls. Make a car radio with a VBox containing two HBoxes with one HBox containing power, a disp
Recreate an interface using JavaFX and any of its associated controls. Make a car radio with a VBox containing two HBoxes with one HBox containing power, a disp

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site