JavaFX | Cylinder with examples - GeeksforGeeks

22 Apr, 2021
Cylinder is a part of JavaFX . Cylinder class is used to create a 3Dimensional cylinder of specified height and radius. The Cylinder is centered at origin. 
The constructor for the class are 
 
Cylinder():Creates a new instance of Cylinder of radius of 1.0 and height of 2.0.Cylinder(double r, double h):Creates a new instance of Cylinder of a given radius and height.Cylinder(double r, double h, int div):Creates a new instance of Cylinder of a given radius and height and divisions
Cylinder():Creates a new instance of Cylinder of radius of 1.0 and height of 2.0.
Cylinder(double r, double h):Creates a new instance of Cylinder of a given radius and height.
Cylinder(double r, double h, int div):Creates a new instance of Cylinder of a given radius and height and divisions
Commonly used methods 
 
 
Java program to create a cylinder and add it to the stage  
This program creates a Cylinder indicated by the name cylinder( the height, and radius is passed as arguments). The Cylinder will be created inside a scene, which in turn will be hosted inside a stage. The function setTitle() is used to provide title to the stage. Then a Group is created, and the cylinder is attached.The group is attached to the scene. Finally, the show() method is called to display the final results.  
Java
// Java program to create a cylinder// and add it to the stageimport javafx.application.Application;import javafx.scene.Scene;import javafx.scene.shape.DrawMode;import javafx.scene.layout.*;import javafx.event.ActionEvent;import javafx.scene.shape.Cylinder;import javafx.scene.control.*;import javafx.stage.Stage;import javafx.scene.Group;public class cylinder_0 extends Application {     // launch the application    public void start(Stage stage)    {        // set title for the stage        stage.setTitle("creating cylinder");         // create a cylinder        Cylinder cylinder = new Cylinder(20.0f, 120.0f);         // create a Group        Group group = new Group(cylinder);         // translate the cylinder to a position        cylinder.setTranslateX(100);        cylinder.setTranslateY(100);         // create a scene        Scene scene = new Scene(group, 500, 300);         // set the scene        stage.setScene(scene);         stage.show();    }     public static void main(String args[])    {        // launch the application        launch(args);    }}
Output: 
 
 
Java program to create a cylinder and add a perspective camera to it  
This program creates a Cylinder indicated by the name cylinder( the height and radius is passed as arguments). The Cylinder will be created inside a scene, which in turn will be hosted inside a stage. The function setTitle() is used to provide title to the stage. Then a Group is created, and the cylinder is attached.The group is attached to the scene. Finally, the show() method is called to display the final results.A perspective camera will be created and added to the scene to render the cylinder in 3D.  
Java
// Java program to create a cylinder and add a perspective camera to it .import javafx.application.Application;import javafx.scene.Scene;import javafx.scene.shape.DrawMode;import javafx.scene.layout.*;import javafx.event.ActionEvent;import javafx.scene.shape.Cylinder;import javafx.scene.control.*;import javafx.stage.Stage;import javafx.scene.Group;import javafx.scene.PerspectiveCamera;public class cylinder_1 extends Application {     // launch the application    public void start(Stage stage)    {        // set title for the stage        stage.setTitle("creating cylinder");         // create a cylinder        Cylinder cylinder = new Cylinder(20.0f, 120.0f);         // create a Group        Group group = new Group(cylinder);         // translate the cylinder to a position        cylinder.setTranslateX(100);        cylinder.setTranslateY(100);         // create a perspective camera        PerspectiveCamera camera = new PerspectiveCamera(false);        camera.setTranslateX(0);        camera.setTranslateY(0);        camera.setTranslateZ(0);         // create a scene        Scene scene = new Scene(group, 500, 300);         scene.setCamera(camera);         // set the scene        stage.setScene(scene);         stage.show();    }     public static void main(String args[])    {        // launch the application        launch(args);    }}
output: 
 
Note : The above programs might not run in an online IDE please use an offline compiler 
Reference: 
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/Cylinder.html 
ManasChhabra2
sweetyty
JavaFX
Java
Java Programs
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Stream In Java
Constructors in Java
Exceptions in Java
Functional Interfaces in Java
Different ways of Reading a text file in Java
Java Programming Examples
Convert Double to Integer in Java
Implementing a Linked List in Java using Class
How to Iterate HashMap in Java?
Program to print ASCII Value of a character