Write an JavaFx application similar to the one in Listing 1.2 that displays a picture of a

Question:

Write an JavaFx application similar to the one in Listing 1.2 that displays a picture of a snowman. Draw three circles, one above the other. Make the circles progressively smaller from bottom to top. Make the top circle a happy face.


Listing 1.2

import javafx.application.Application;
import javafx.scene.canvas.Canvas;
10
import javafx.scene.Scene;
import javafx.scene.Group;
import javafx.stage.Stage;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.shape.ArcType;
public class HappyFace extends Application
{
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception
{
Group root = new Group();
Scene scene = new Scene(root);
Canvas canvas = new Canvas(400, 300);
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.strokeOval(100, 50, 200, 200);
gc.fillOval(155, 100, 10, 20);
gc.fillOval(230, 100, 10, 20);
gc.strokeArc(150, 160, 100, 50, 180, 180, ArcType.OPEN);
root.getChildren().add(canvas);
primaryStage.setTitle("HappyFace in JavaFX");
primaryStage.setScene(scene);
primaryStage.show();
}
}

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: