import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.shape.ArcType; import javafx.stage.Stage; import static javafx.application.Application.launch; import javafx.scene.paint.Color; /** * This is a slightly tweaked version of the happy face code from section 1.4 of * the textbook. * * @author Sam Scott * @author Walter Savitch */ public class HappyFace extends Application { /** * Start method (use this instead of main). * * @param stage The FX stage to draw on * @throws Exception */ @Override public void start(Stage stage) throws Exception { Group root = new Group(); Scene scene = new Scene(root); Canvas canvas = new Canvas(400, 300); root.getChildren().add(canvas); stage.setScene(scene); stage.show(); GraphicsContext gc = canvas.getGraphicsContext2D(); // YOUR STUFF GOES HERE (remove the code below) stage.setTitle("Happy Face"); //face outline gc.strokeOval(100, 50, 200, 200); //eyes gc.strokeOval(155, 100, 20, 30); gc.strokeOval(230, 100, 20, 30); //pupils gc.setFill(Color.BLUE); gc.fillOval(165,112,5,10); gc.fillOval(244,112,5,10); //mouth gc.strokeArc(150, 160, 100, 50, 180, 180, ArcType.OPEN); //nose gc.setFill(Color.BLACK); gc.strokeOval(190,130,25,50); //how do draw lines //gc.setLineWidth(10); //gc.strokeLine(0,0, 400,400); } /** * The actual main method that launches the app * * @param args unused */ public static void main(String[] args) { launch(args); } }