用java写cylinder_JavaFX 类 Cylinder用法及代码示例

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);

}

}

输出:

7af220fb3bf3d1cac22cd6d8cab1b429.png

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);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值