如何利用JavaFx写一个旋转的圆柱?

import javafx.application.Application;
import javafx.animation.RotateTransition;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Cylinder;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
import javafx.util.Duration;


public class ArcPane extends Application{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		launch(args);

	}

	@Override
	public void start(Stage stage) throws Exception {
		// TODO Auto-generated method stub
		// Drawing a Cylinder
        Cylinder cylinder = new Cylinder();

        // Setting the properties of the Cylinder
        cylinder.setHeight(180.0f);
        cylinder.setRadius(100.0f);

        // Preparing the phong material of type diffuse color
        PhongMaterial material = new PhongMaterial();
        material.setDiffuseColor(Color.BLANCHEDALMOND);

        // Setting the diffuse color material to Cylinder5
        cylinder.setMaterial(material);

        // Setting rotation transition for the cylinder
        RotateTransition rotateTransition = new RotateTransition();

        // Setting the duration for the transition
        rotateTransition.setDuration(Duration.millis(1000));

        // Setting the node for the transition
        rotateTransition.setNode(cylinder);

        // Setting the axis of the rotation
        rotateTransition.setAxis(Rotate.X_AXIS);

        // Setting the angle of the rotation
        rotateTransition.setByAngle(360);

        // Setting the cycle count for the transition
        rotateTransition.setCycleCount(RotateTransition.INDEFINITE);

        // Setting auto reverse value to false
        rotateTransition.setAutoReverse(false);

        // playing the animation
        rotateTransition.play();

        // Creating an Anchor Pane
        AnchorPane anchorPane = new AnchorPane();

        // Setting the anchor to the cylinder
        AnchorPane.setTopAnchor(cylinder, 50.0);
        AnchorPane.setLeftAnchor(cylinder, 50.0);
        AnchorPane.setRightAnchor(cylinder, 50.0);
        AnchorPane.setBottomAnchor(cylinder, 50.0);

        // Retrieving the observable list of the Anchor Pane
        ObservableList list = anchorPane.getChildren();

        // Adding cylinder to the pane
        list.addAll(cylinder);

        // Creating a scene object
        Scene scene = new Scene(anchorPane);

        // Setting title to the Stage
        stage.setTitle("Anchor Pane Example");

        // Adding scene to the stage
        stage.setScene(scene);

        // Displaying the contents of the stage
        stage.show();
    }
		
	}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值