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; /** * This program is a virtual baseball pitch counter app. * * @author Dave Slemon */ public class PitchCountApp extends Application { // TODO: Instance Variables for View Components and Model private Counter c; private Label appTitle; private TextField inputBox; private Button incrementButton; private Button resetButton; // TODO: Private Event Handlers and Helper Methods private void resetHandler(ActionEvent e) { c.reset(); inputBox.setText(c.toString()); } private void incrementButtonRoutine(ActionEvent e) { String str = inputBox.getText(); c.setCount(str); c.increment(); inputBox.setText(c.toString()); } /** * 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, 400, 225); // set the size here stage.setTitle("Pitch Counter"); // set the window title here stage.setScene(scene); // TODO: Add your GUI-building code here scene.getStylesheets().add("myStyles.css"); // 1. Create the model c = new Counter(); // 2. Create the GUI components appTitle = new Label("Pitch Counter"); inputBox = new TextField("0"); incrementButton = new Button("Increment"); resetButton = new Button("Reset"); // 3. Add components to the root root.getChildren().addAll(appTitle,inputBox,incrementButton, resetButton); // 4. Configure the components (colors, fonts, size, location) appTitle.relocate(85,35); appTitle.setFont( new Font("Arial",40)); appTitle.setStyle("-fx-text-fill: green;"); inputBox.relocate(110,100); inputBox.setFont( new Font("Arial",25)); inputBox.setPrefWidth(120); inputBox.setPrefHeight(50); incrementButton.relocate(50,160); //incrementButton.setFont(new Font("System",25)); resetButton.relocate(230,160); resetButton.setId("resetButton"); //resetButton.setFont(new Font("System",25)); // 5. Add Event Handlers and do final setup resetButton.setOnAction(this::resetHandler); incrementButton.setOnAction(this::incrementButtonRoutine); // 6. Show the stage stage.show(); } /** * Make no changes here. * * @param args unused */ public static void main(String[] args) { launch(args); } }