Problem

(Display country flag and flag description) Listing 1, ComboBoxDemo.java, gives a program...

(Display country flag and flag description) Listing 1, ComboBoxDemo.java, gives a program that lets the user view a country’s flag image and description by selecting the country from a combo box. The description is a string coded in the program. Rewrite the program to read the text description from a file. Suppose that the descriptions are stored in the files description0.txt, . . . , and description8.txt under the text directory for the nine countries Canada, China, Denmark, France, Germany, India, Norway, United Kingdom, and United States, in this order.

LISTING 1 RadioButtonDemo.java

1 import javafx.geometry.Insets;

2 import javafx.scene.control.RadioButton;

3 import javafx.scene.control.ToggleGroup;

4 import javafx.scene.layout.BorderPane;

5 import javafx.scene.layout.VBox;

6 import javafx.scene.paint.Color;

7

8 public class RadioButtonDemo extends CheckBoxDemo {

9 @Override // Override the getPane() method in the super class

10 protected BorderPane getPane() {

11 BorderPane pane = super.getPane();

12

13 VBox paneForRadioButtons = new VBox(20);

14 paneForRadioButtons.setPadding(new Insets(5, 5, 5, 5));

15 paneForRadioButtons.setStyle("-fx-border-color: green");

16 paneForRadioButtons.setStyle

17 ("-fx-border-width: 2px; -fx-border-color: green");

18 RadioButton rbRed = new RadioButton("Red");

19 RadioButton rbGreen = new RadioButton("Green");

20 RadioButton rbBlue = new RadioButton("Blue");

21 paneForRadioButtons.getChildren().addAll(rbRed, rbGreen, rbBlue);

22 pane.setLeft(paneForRadioButtons);

23

24 ToggleGroup group = new ToggleGroup();

25 rbRed.setToggleGroup(group);

26 rbGreen.setToggleGroup(group);

27 rbBlue.setToggleGroup(group);

28

29 rbRed.setOnAction(e -> {

30 if (rbRed.isSelected()) {

31 text.setFill(Color.RED);

32 }

33 });

34

35 rbGreen.setOnAction(e -> {

36 if (rbGreen.isSelected()) {

37 text.setFill(Color.GREEN);

38 }

39 });

40

41 rbBlue.setOnAction(e -> {

42 if (rbBlue.isSelected()) {

43 text.setFill(Color.BLUE);

44 }

45 });

46

47 return pane;

48 }

49 }

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT