import static javafx.scene.paint.Color.BLUE; import static javafx.scene.paint.Color.CYAN; import static javafx.scene.paint.Color.GREEN; import static javafx.scene.paint.Color.MAGENTA; import static javafx.scene.paint.Color.ORANGE; import static javafx.scene.paint.Color.RED; import static javafx.scene.paint.Color.YELLOW; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.stage.Stage; public class ShapeTest extends Application { public void start(Stage stage) { stage.setTitle("Shape Test"); final Canvas canvas = new Canvas(200, 150); GraphicsContext gc = canvas.getGraphicsContext2D(); double[] xs = {100, 137, 175, 175, 137, 100}; double[] ys = { 0, 0, 25, 50, 50, 25}; gc.setStroke(RED); gc.strokeLine(0, 0, 75, 50); gc.setStroke(GREEN); gc.strokeRect(0, 0, 75, 50); gc.setStroke(BLUE); gc.strokeOval(0, 75, 75, 50); gc.setStroke(ORANGE); gc.strokePolygon(xs, ys, 6); gc.setFill(CYAN); gc.fillRect(90, 65, 75, 50); gc.setFill(MAGENTA); gc.fillRect(100, 75, 75, 50); gc.setFill(YELLOW); gc.fillRect(110, 85, 75, 50); Group root = new Group(); root.getChildren().addAll(canvas); Scene scene = new Scene(root); stage.setScene(scene); stage.show(); } public static void main(String... args) { launch(args); } }