我需要使用6个矩形进行旋转。 我想连接矩形,但不能。 怎么做?谢谢! (我不能使用盒子,只能使用矩形!)
我尝试了Union。 然后我尝试了这个小组。
FXML控制器:
package rectangle3dfxml;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Group;
import javafx.scene.control.Slider;
import javafx.scene.layout.AnchorPane;
import javafx.scene.shape.Rectangle;
import javafx.scene.transform.Rotate;
import javafx.scene.shape.Shape;
public class FXMLDocumentController implements Initializable {
@FXML
private AnchorPane AnchorPane1;
@FXML
private Slider sliderY;
@FXML
private Slider sliderX;
@FXML
private Slider sliderZ;
@FXML
private Rectangle rectangleRed;
@FXML
private Rectangle rectangleBlue;
@FXML
private Rectangle rectangleGreen;
@FXML
private Rectangle rectangleYellow;
@FXML
private Rectangle rectangleBlack;
@FXML
private Rectangle rectanglePurple;
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
//attempt #1
// Shape unionShape1 = Shape.union(rectangleRed,rectangleBlue);
// Shape unionShape2 = Shape.union(rectangleGreen,rectangleYellow);
// Shape unionShape3 = Shape.union(rectangleBlack, rectanglePurple);
// Shape unionShape4 = Shape.union(unionShape1, unionShape2);
// Shape unionShape5 = Shape.union(unionShape4, unionShape3);
//attempt #2
Group group = new Group();
group.getChildren().addAll(rectangleRed,rectangleBlue,rectangleGreen,rectangleYellow,rectangleBlack,rectanglePurple);
sliderX.valueProperty().addListener((observable, oldValue, newValue) -> {
group.setRotationAxis(Rotate.X_AXIS);
group.setRotate((double) newValue);
});
sliderY.valueProperty().addListener((observable, oldValue, newValue) -> {
group.setRotationAxis(Rotate.Y_AXIS);
group.setRotate((double) newValue);
});
sliderZ.valueProperty().addListener((observable, oldValue, newValue) -> {
group.setRotationAxis(Rotate.Z_AXIS);
group.setRotate((double) newValue);
});
}
}
我没有收到错误消息。 但这不起作用。 我只看到3个滑块。