JavaFX Line create cylinder
import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import javafx.scene.shape.Arc; import javafx.scene.shape.ArcType; import javafx.scene.shape.Line; import javafx.stage.Stage; public class Main extends Application { @Override//w w w. j av a 2 s . c om public void start(Stage primaryStage) { CylinderPane pane = new CylinderPane(200, 200 / 2.5); pane.setPadding(new Insets(20)); Scene scene = new Scene(pane); primaryStage.setTitle("E14_10"); primaryStage.setScene(scene); primaryStage.setResizable(false); primaryStage.show(); } public static void main(String[] args) { Application.launch(args); } } class CylinderPane extends StackPane { CylinderPane(double xRadius, double yRadius) { // Container pane for all the shapes Pane pane = new Pane(); // The top ellipse Arc topArc = new Arc(xRadius, yRadius, xRadius, yRadius, 0, 360); topArc.setFill(Color.WHITE); topArc.setStroke(Color.BLACK); Arc bottomDash = new Arc(xRadius, yRadius + yRadius * 5, xRadius, yRadius, 0, 180); bottomDash.setFill(Color.WHITE); bottomDash.setStroke(Color.BLACK); bottomDash.getStrokeDashArray().addAll(6.0, 21.0); Arc bottomSolid = new Arc(xRadius, yRadius + yRadius * 5, xRadius, yRadius, 180, 180); bottomSolid.setFill(Color.WHITE); bottomSolid.setStroke(Color.BLACK); bottomSolid.setType(ArcType.OPEN); // The lines connecting the top and bottom ellipses. Line leftLine = new Line(0, yRadius, 0, yRadius + yRadius * 5); leftLine.setStroke(Color.BLACK); Line rightLine = new Line(xRadius * 2, yRadius, xRadius * 2, yRadius + yRadius * 5); // Shapes added to container pane.getChildren().addAll(topArc, bottomDash, bottomSolid, leftLine, rightLine); // Container added to StackPane for presentation getChildren().add(pane); } }