Cylinder是JavaFX的一部分。圆柱体类用于创建指定高度和半径的3Dimensional圆柱体。圆柱体以原点为中心。
该类的构造函数是
Cylinder():创建一个半径为1.0且高度为2.0的Cylinder的新实例。
Cylinder(double r, double h):创建给定半径和高度的Cylinder的新实例。
Cylinder(double r, double h, int div):创建给定半径,高度和分度的Cylinder的新实例
常用方法
方法
说明
getHeight()
返回圆柱体的高度
getRadius()
返回圆柱体底面的半径
setHeight(double v)
设置圆柱体的高度
setRadius(double v)
设置圆柱体的半径
Java program to create a cylinder and add it to the stage
此程序将创建一个由圆柱体名称表示的圆柱体(高度和半径作为参数传递)。圆柱体将在场景内创建,而场景又将在场景内托管。函数setTitle()用于为舞台提供标题。然后创建一个组,然后将圆柱体附加到该组。最后,调用show()方法以显示最终结果。
// Java program to create a cylinder
// and add it to the stage
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;
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);
}
}
输出:
Java program to create a cylinder and add a perspective camera to it
此程序将创建一个由圆柱体名称表示的圆柱体(高度和半径作为参数传递)。圆柱体将在场景内创建,而场景又将在场景内托管。函数setTitle()用于为舞台提供标题。然后创建一个组,然后将圆柱体附加到该组。最后,调用show()方法以显示最终结果。将创建一个透视相机并将其添加到场景中以3D渲染圆柱体。
// 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);
}
}