Answer to Question #265039 in Java | JSP | JSF for Ashwari Pillay

Question #265039

On the form create two combo boxes, one for the country selection and another to select a town. Also, add two radio buttons for the user to select to display either a phone or postal code.


You are also required to create a menu system which will allow the user to exit the application under the file menu. Under the tools menu allow the form submission and option to display the average yearly petrol price report. The layout of the form is left to your discretion. Marks will be allocated to the presentation and effectiveness of the layout, but the following layout is displayed for your convenience.




SOUTH AFRICA UNITED KINGDOM

Cape Town London

Phone Code: 021 Phone Code: 020

Postal Code: 8000 Postal Code: WC2N5DU

Johannesburg Oxford

Phone Code: 011 Phone Code: 01865

Postal Code: 2000 Postal Code: OX13PN


Durban Southampton

Phone Code: 031 Phone Code: 023

Postal Code: 4000 Postal Code: SO147DW 


1
Expert's answer
2021-11-12T16:30:53-0500
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Main extends Application {
 @Override
 public void start(Stage primaryStage) throws Exception {
 String[][] towns = {{"Cape Town", "Johannesburg", "Polokwane"}, {"London", "Liverpool", "Manchester"}};
 ComboBox<String> townsComboBox = new ComboBox<>();
 ComboBox<String> countriesComboBox = new ComboBox<>(FXCollections.observableArrayList("South Africa", "United Kingdom"));
 countriesComboBox.setOnAction((ActionEvent event) -> {
 int selectedIndex = countriesComboBox.getSelectionModel().getSelectedIndex();
 if (selectedIndex != -1) {
 townsComboBox.setItems(FXCollections.observableArrayList(towns[selectedIndex]));
 }
 });
 RadioButton postalCodeRadioButton = new RadioButton("Postal code");
 postalCodeRadioButton.setOnAction((ActionEvent event) -> {
 System.out.println("Selected postal");
 });
 RadioButton phoneCodeRadioButton = new RadioButton("Phone code");
 phoneCodeRadioButton.setOnAction((ActionEvent event) -> {
 System.out.println("Selected phone");
 });
 ToggleGroup toggleGroup = new ToggleGroup();
 toggleGroup.getToggles().addAll(postalCodeRadioButton, phoneCodeRadioButton);

 MenuItem exitMenuItem = new MenuItem("Exit");
 exitMenuItem.setOnAction((ActionEvent event) -> {
 System.exit(0);

 });
 MenuItem submissionMenuItem = new MenuItem("Submission");
 submissionMenuItem.setOnAction((ActionEvent event) -> {

 });
 MenuItem priceReportMenuItem = new MenuItem("Price Report");
 priceReportMenuItem.setOnAction((ActionEvent event) -> {

 });

 Menu fileMenu = new Menu("File");
 fileMenu.getItems().add(exitMenuItem);

 Menu toolsMenu = new Menu("Tools");
 toolsMenu.getItems().addAll(submissionMenuItem, priceReportMenuItem);

 MenuBar menuBar = new MenuBar(fileMenu, toolsMenu);

 VBox comboBoxesVBox = new VBox(10, countriesComboBox, townsComboBox, postalCodeRadioButton, phoneCodeRadioButton);
 comboBoxesVBox.setAlignment(Pos.CENTER);

 BorderPane borderPane = new BorderPane();

 borderPane.setTop(menuBar);
 borderPane.setCenter(comboBoxesVBox);

 primaryStage.setScene(new Scene(borderPane, 800, 600));
 primaryStage.show();
 }

 public static void main(String[] args) {
 launch(args);
 }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS