package com.example.javafxproject;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.shape.Polyline;
import javafx.stage.Stage;
public class BeanMachine extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Scene scene = new Scene(getPane(), 500, 300);
primaryStage.setScene(scene);
primaryStage.setTitle("时钟");
primaryStage.show();
}
private Pane getPane() {
Group group = new Group();
Polyline polyline = new Polyline(190, 20, 190, 40, 115, //瓶子形状
190, 115, 230, 300, 230, 300, 190, 225, 40, 225, 20);
double startX = 135, startY = 190;
double endX = 135, endY = 230;
for (int i = 0; i < 7; i++) { //组依次添加线
group.getChildren().add(new Line(startX, startY, endX, endY));
startX += 24.13;
endX += 24.13;
}
double centerX = 135, centerY = 190, radius = 5;
for (int i = 0; i < 7; i++) { //组依次添加黑色圆
double x = centerX, y = centerY;
for (int j = i; j < 7; j++) {
Circle circle = new Circle(x, y, radius);
group.getChildren().add(circle);
x += 24.13;
}
centerX += 24.13 / 2;
centerY -= 24.13;
}
group.getChildren().addAll(polyline);
return new BorderPane(group);
}
}