line.setRotate( 45.0 );
Here is a program that draws a barbell in the center of the window. As written, the barbell is horizontal.
The barbell consists of a horizontal Line connecting two Circles.
These three Nodes are put into a Group
referred to by bb.
Then that barbell group is made a child of the Group that is the root of the scene graph.
import javafx.application.*;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.shape.*;
import javafx.scene.paint.*;
public class DrawBarBell extends Application
{
void addBarBell( Group root, double centerX, double centerY, double size, double degrees)
{
Group bb = new Group()
// Make a horizontal bar
Line bar = new Line( centerX-size/2, centerY, centerX+size/2, centerY );
bar.setStrokeWidth( 8.0 );
bar.setStroke( Color.SILVER );
bb.getChildren().add( bar ); // put bar in the barbell Group
// Make a circle
double radius = size/6.0;
Circle leftBell = new Circle( centerX-size/2, centerY, radius, Color.DARKSLATEGREY);
bb.getChildren().add( leftBell ); // put the circle into the barbell Group
// Make another circle
Circle rightBell = new Circle( centerX+size/2, centerY, radius, Color.DARKSLATEGREY);
bb.getChildren().add( rightBell ); // put the circle into the barbell Group
// Put the barbell Group into the Group that is the root of the scene graph
root.getChildren().add( bb );
}
public void start(Stage stage)
{
double sceneWidth=400, sceneHeight= 300;
Group root = new Group( );
addBarBell( root, sceneWidth/2, sceneHeight/2, sceneWidth*0.7, 30.0 );
Scene scene = new Scene(root, sceneWidth, sceneHeight, Color.BLANCHEDALMOND );
stage.setTitle("Bar Bell");
stage.setScene(scene);
stage.show();
}
}
Can a Group be a child of a Group?