The objective of the assignment is to write a GUI app using check boxes and comb
ID: 3866573 • Letter: T
Question
The objective of the assignment is to write a GUI app using check boxes and combo boxes to create GUI objects using JavaFx.
INSTRUCTIONS: Cindy’s catering provides meals for parties and special events. Create an interactive GUI program that allows Cindy's Catering to better operate their business. The following data must be entered concerning the customer and the event:
1. The customer’s name must be entered into a text field.
2. The customer’s contact phone number into a text field.
3. The number of guests invited to a Cindy catered event into a text field.
4. The customer must choose one entrée from a group of at least four choices.
5. The customer must choose up to two side dishes from a group of at least four choices.
6. The customer must choose one desert from a group of at least three choices.
Display the cost of the event which is calculated as $35 per person.To validate the input data, do the following: If the value entered for the number of guest is not numeric, set the event price to zero. And If the user attempts to choose more than two side dishes, remove all the current side dish selections so that the user can start over.
After the final price for the dinner has been calculated, the event information must be saved to an output file so that Cindy’s Catering will have the information for the event. The items should be separated by spaces. If any item is not chosen, enter the word “none” for that item. The following fields must be written to the output file: The customer’s name, phone number, number of guests, the one entree chosen, the two sides chosen, the one desert chosen.
Requirements: The data input must be done with a GUI
Explanation / Answer
import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.GridPane; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.util.Callback; public class ComboBoxSample extends Application { public static void main(String[] args) { launch(args); } final Button button = new Button ("Send"); final Label notification = new Label (); final TextField subject = new TextField(""); final TextArea text = new TextArea (""); String address = " "; @Override public void start(Stage stage) { stage.setTitle("ComboBoxSample"); Scene scene = new Scene(new Group(), 450, 250); final ComboBox emailComboBox = new ComboBox(); emailComboBox.getItems().addAll( "jacob.smith@example.com", "isabella.johnson@example.com", "ethan.williams@example.com", "emma.jones@example.com", "michael.brown@example.com" ); emailComboBox.setPromptText("Email address"); emailComboBox.setEditable(true); emailComboBox.valueProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue ov, String t, String t1) { address = t1; } }); final ComboBox priorityComboBox = new ComboBox(); priorityComboBox.getItems().addAll( "Highest", "High", "Normal", "Low", "Lowest" ); priorityComboBox.setValue("Normal"); priorityComboBox.setCellFactory( new Callback() { @Override public ListCell call(ListView param) { final ListCell cell = new ListCell() { { super.setPrefWidth(100); } @Override public void updateItem(String item, boolean empty) { super.updateItem(item, empty); if (item != null) { setText(item); if (item.contains("High")) { setTextFill(Color.RED); } else if (item.contains("Low")){ setTextFill(Color.GREEN); } else { setTextFill(Color.BLACK); } } else { setText(null); } } }; return cell; } }); button.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) { if (emailComboBox.getValue() != null && !emailComboBox.getValue().toString().isEmpty()){ notification.setText("Your message was successfully sent" + " to " + address); emailComboBox.setValue(null); if (priorityComboBox.getValue() != null && !priorityComboBox.getValue().toString().isEmpty()){ priorityComboBox.setValue(null); } subject.clear(); text.clear(); } else { notification.setText("You have not selected a recipient!"); } } }); GridPane grid = new GridPane(); grid.setVgap(4); grid.setHgap(10); grid.setPadding(new Insets(5, 5, 5, 5)); grid.add(new Label("To: "), 0, 0); grid.add(emailComboBox, 1, 0); grid.add(new Label("Priority: "), 2, 0); grid.add(priorityComboBox, 3, 0); grid.add(new Label("Subject: "), 0, 1); grid.add(subject, 1, 1, 3, 1); grid.add(text, 0, 2, 4, 1); grid.add(button, 0, 3); grid.add (notification, 1, 3, 3, 1); Group root = (Group)scene.getRoot(); root.getChildren().add(grid); stage.setScene(scene); stage.show(); } }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.