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);
}
}
我期待第一個路徑是黃色,第二是紅色的,但我有這樣的結果,而不是
我在做什麼錯? 在此先感謝。