0
我一直在尝试将不同的颜色设置为两个SVG路径。但是,看起来SVG Paths中的一个获得了与第二个相同的属性。下面是代码:将不同的颜色设置为svg路径
public class MainApp extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Drawing Operations Test");
Group root = new Group();
Canvas canvas = new Canvas(400, 400);
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.setFill(Color.YELLOW);
gc.setStroke(Color.YELLOW);
gc.appendSVGPath("M 50 50 L 150 50 L 100 150 z");
//gc.fill(); //If I uncomment these two lines, the second
//gc.stroke(); //path won't appear
gc.setFill(Color.RED);
gc.setStroke(Color.BLUE);
gc.appendSVGPath("M 200 50 L 300 50 L 250 150 z");
gc.fill();
gc.stroke();
root.getChildren().add(canvas);
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
我期待第一个路径是黄色,第二是红色的,但我有这样的结果,而不是
我在做什么错? 在此先感谢。