import javafx.scene.control.*; import javafx.scene.text.Font; import javafx.event.ActionEvent; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.stage.Stage; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.control.CheckBox; /** * This program allows you to make pizza orders. * * @author Dave Slemon * @version v100 */ public class TestProgram extends Application { // TODO: Instance Variables for View Components and Model Pizza pizza = new Pizza(""); TextField textField = new TextField("0.00"); Item nothing = new Item(); Item item1 = new Item("pepperoni"); Item item2 = new Item("mushrooms"); Item item3 = new Item("green peppers"); CheckBox checkBox1 = new CheckBox(item1.getName()); CheckBox checkBox2 = new CheckBox(item2.getName()); CheckBox checkBox3 = new CheckBox(item3.getName()); ComboBox comboBox = new ComboBox(); private String chosenSize; // TODO: Private Event Handlers and Helper Methods public void newOrderButtonHandler(ActionEvent e) { if (pizza.getSize().length() > 0) { pizza.setToppings( (checkBox1.isSelected()?item1:nothing), (checkBox2.isSelected()?item2:nothing), (checkBox3.isSelected()?item3:nothing) ); updateTotal(); System.out.printf("$%5.2f\t%s\n",+pizza.getCost(), pizza.toString()); } } public void clearButtonHandler(ActionEvent e) { pizza.setToppings(nothing, nothing, nothing); checkBox1.setSelected(false); checkBox2.setSelected(false); checkBox3.setSelected(false); pizza.setSize(""); comboBox.setValue(""); pizza.setToppings(nothing, nothing, nothing); updateTotal(); //textField.setText("0.00"); } public void comboBoxHandler(String chosenSize) { //this.chosenSize = chosenSize; pizza.setSize(chosenSize); pizza.setToppings( (checkBox1.isSelected()?item1:nothing), (checkBox2.isSelected()?item2:nothing), (checkBox3.isSelected()?item3:nothing) ); updateTotal(); } public void checkBoxHandler() { updateTotal(); } public void updateTotal() { pizza.setToppings( (checkBox1.isSelected()?item1:nothing), (checkBox2.isSelected()?item2:nothing), (checkBox3.isSelected()?item3:nothing) ); double subTotal = pizza.getCost(); String str = String.format("%.2f",subTotal); textField.setText(str); } /** * This is where you create your components and the model and add event * handlers. * * @param stage The main stage * @throws Exception */ @Override public void start(Stage stage) throws Exception { Pane root = new Pane(); Scene scene = new Scene(root, 700, 500); // set the size here stage.setTitle("Dave's Pizza Shop"); // set the window title here stage.setScene(scene); scene.getStylesheets().add("pizza.css"); // TODO: Add your GUI-building code here // 1. Create the model pizza = new Pizza(""); // 2. Create the GUI components Image image = new Image("pizza.png"); //Setting the image view ImageView imageView = new ImageView(image); //Setting the position of the image imageView.setX(450); imageView.setY(5); //setting the fit height and width of the image view imageView.setFitHeight(230); imageView.setFitWidth(230); //Setting the preserve ratio of the image view imageView.setPreserveRatio(true); Button newOrderButton = new Button("Order Pizza"); Button clearButton = new Button("Clear"); Label title = new Label("Dave's Pizza Shop"); // 3. Add components to the root root.getChildren().addAll( title, newOrderButton, comboBox, textField, imageView, checkBox1, checkBox2, checkBox3, clearButton ); // 4. Configure the components (colors, fonts, size, location) //New Order Button newOrderButton.relocate(250,400); newOrderButton.setPrefHeight(40); newOrderButton.setFont(new Font("System",20)); //Clear Button clearButton.relocate(150,400); clearButton.setPrefHeight(40); clearButton.setFont(new Font("System",20)); //Dave's Pizza Shop banner title title.relocate(50,25); title.setFont(new Font("System",40)); title.setStyle("-fx-text-fill: blue;"); comboBox.getItems().addAll( "Large", "Medium", "Small" ); comboBox.setStyle("-fx-font: 22px \"Serif\";"); comboBox.relocate(50,150); comboBox.setPrefWidth(250); comboBox.setPrefHeight(50); //comboBox.setValue("Large"); comboBox.setMaxWidth(250); //Total cost box textField.relocate(500,400); textField.setPrefWidth(120); textField.setPrefHeight(50); textField.setFont(new Font("System",25)); checkBox1.relocate(50, 250); checkBox1.setFont(new Font("System",25)); checkBox2.relocate(250, 250); checkBox2.setFont(new Font("System",25)); checkBox3.relocate(470, 250); checkBox3.setFont(new Font("System",25)); // 5. Add Event Handlers and do final setup newOrderButton.setOnAction ( this::newOrderButtonHandler ); clearButton.setOnAction ( this::clearButtonHandler ); comboBox.setOnAction((e) -> { comboBoxHandler(comboBox.getSelectionModel().getSelectedItem().toString()); }); checkBox1.setOnAction((e) -> { checkBoxHandler(); }); checkBox2.setOnAction((e) -> { checkBoxHandler(); }); checkBox3.setOnAction((e) -> { checkBoxHandler(); }); // 6. Show the stage stage.show(); } /** * Make no changes here. * * @param args unused */ public static void main(String[] args) { launch(args); } }