下面列出了javafx.scene.shape.Polyline#getPoints ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
// Create a pane
Pane pane = new Pane();
// Create a polyline
Polyline polyline = new Polyline(new Double(100.0), new Double(100.0));
polyline.setFill(Color.WHITE);
polyline.setStroke(Color.BLACK);
pane.getChildren().add(polyline);
ObservableList<Double> list = polyline.getPoints();
// Create and register handler
pane.setOnKeyPressed(e -> {
double x = 0, y = 0;
double length = 10;
switch (e.getCode()) {
case DOWN: x = list.get(list.size() - 2);
y = list.get(list.size() - 1) + length; break;
case UP: x = list.get(list.size() - 2);
y = list.get(list.size() - 1) - length; break;
case RIGHT: x = list.get(list.size() - 2) + length;
y = list.get(list.size() - 1); break;
case LEFT: x = list.get(list.size() - 2) - length;
y = list.get(list.size() - 1); break;
}
list.add(x);
list.add(y);
});
// Create a scene and place it in the stage
Scene scene = new Scene(pane, 200, 200);
primaryStage.setTitle("Exercise_15_09"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
pane.requestFocus(); // Pane is focused to receive key input
}
public static String convertPolyline(final Polyline POLYLINE) {
final StringBuilder fxPath = new StringBuilder();
final int size = POLYLINE.getPoints().size();
if (size % 2 == 0) {
List<Double> coordinates = POLYLINE.getPoints();
for (int i = 0 ; i < size ; i += 2) {
fxPath.append(i == 0 ? "M " : "L ")
.append(coordinates.get(i)).append(" ").append(coordinates.get(i + 1)).append(" ");
}
}
return fxPath.toString();
}
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
// Create two panes
Pane pane1 = new Pane();
pane1.setRotate(180);
pane1.setPadding(new Insets(72, 0, 0, 75));
Pane pane2 = new Pane();
// Create a polyline
Polyline polyline1 = new Polyline();
pane1.getChildren().add(polyline1);
ObservableList<Double> list = polyline1.getPoints();
double scaleFactor = 0.0125;
for (int x = -100; x <= 100; x++) {
list.add(x + 200.0);
list.add(scaleFactor * x * x);
}
// Create two lines
Line lineX = new Line(10, 200, 350, 200);
//pane.getChildren().addAll(stackPane, lineX);
Line lineY = new Line(lineX.getEndX() / 2, 250, lineX.getEndX() / 2, 30);
pane2.getChildren().addAll(pane1, lineX, lineY);
// Create two polylines
Polyline polyline2 = new Polyline();
pane2.getChildren().add(polyline2);
ObservableList<Double> list2 = polyline2.getPoints();
list2.addAll(lineY.getEndX() - 10, lineY.getEndY() + 20,
lineY.getEndX(), lineY.getEndY(), lineY.getEndX() + 10,
lineY. getEndY() + 20);
Polyline polyline3 = new Polyline();
pane2.getChildren().add(polyline3);
ObservableList<Double> list3 = polyline3.getPoints();
list3.addAll(lineX.getEndX() - 20, lineX.getEndY() - 10,
lineX.getEndX(), lineX.getEndY(), lineX.getEndX() - 20,
lineX. getEndY() + 10);
// Create two text objects
Text textX = new Text(lineX.getEndX() - 10, lineX.getEndY() - 20, "X");
Text textY = new Text(lineY.getEndX() + 20, lineY.getEndY() + 10, "Y");
pane2.getChildren().addAll(textX, textY);
// Create a scene and place it in the stage
Scene scene = new Scene(pane2);
primaryStage.setTitle("Exercise_14_18"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
// Create a pane
Pane pane = new Pane();
// Create three polylines and set their properties
Polyline polyline1 = new Polyline();
pane.getChildren().add(polyline1);
polyline1.setStroke(Color.BLACK);
ObservableList<Double> list = polyline1.getPoints();
double x1 = 40.0;
double y1 = 190.0;
double y2 = 20.0;
double x3 = 125.0;
list.addAll(x1, y1, x1, y2, x3, y2, x3, y1 * .60);
Polyline polyline2 = new Polyline();
pane.getChildren().add(polyline2);
polyline2.setStroke(Color.BLACK);
ObservableList<Double> list2 = polyline2.getPoints();
list2.addAll((x1 + x3) * .5, y1 * .5, x3, y1 * .25,
x3 + (x3 - x1) * .5, y1 * .5);
Polyline polyline3 = new Polyline();
pane.getChildren().add(polyline3);
polyline3.setStroke(Color.BLACK);
ObservableList<Double> list3 = polyline3.getPoints();
list3.addAll((x1 + x3) * .6, y1 * .80, x3, y1 * .60,
x3 + (x3 - x1) * .3, y1 * .80);
// Create a circle and set its properties
Circle circle = new Circle(x3, y1 * .25, 15);
circle.setFill(Color.WHITE);
circle.setStroke(Color.BLACK);
pane.getChildren().add(circle);
// Create an arc and set its properties
Arc arc = new Arc(x1, y1 + 1, 25, 15, 0, 180);
arc.setFill(Color.WHITE);
arc.setStroke(Color.BLACK);
pane.getChildren().add(arc);
// Create a scene and place it in the stage
Scene scene = new Scene(pane, 200, 200);
primaryStage.setTitle("Exercise_14_17"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}