import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.BorderPane; import javafx.scene.layout.FlowPane; import javafx.stage.Stage; public class PaintApp extends Application { // constants private static final int APP_WIDTH = 800; private static final int APP_HEIGHT = 650; private static final int CANVAS_HEIGHT = 600; // GUI variables private BorderPane mainPane; private FlowPane controlPanel; private MyCanvas canvas; private Button bnClear; @Override public void start(Stage stage) { mainPane = new BorderPane(); setupControls(); setupCanvas(); Scene scene = new Scene(mainPane, APP_WIDTH, APP_HEIGHT); stage.setTitle("CS112 PaintApp FX"); stage.setScene(scene); stage.show(); } private void setupControls() { // Q. flow pane vs. hbox? controlPanel = new FlowPane(); mainPane.setTop(controlPanel); bnClear = new Button("Clear Canvas"); controlPanel.getChildren().addAll(bnClear); } private void setupCanvas() { canvas = new MyCanvas(APP_WIDTH, CANVAS_HEIGHT); // listener: MouseDragged canvas.setOnMouseDragged(e -> { // 1. get user's mouse location from e (of MouseEvent type) int mx = (int) e.getX(); int my = (int) e.getY(); // 2. create one CircularStroke at location from (1) Stroke s = new CircularStroke(mx, my, 2, true); // 3. add the stroke from (2) to canvas canvas.addStroke(s); }); } public static void main(String[] args) { launch(args); } }