Yes. This is often very useful
The Nodes in the scene graph are drawn in the order they were added.
So, in this case, the Line (the bar) is added first so that the Circles
overlap it.
A transformation can be applied to a Group.
When this is done,
the transformation affects all the children of the Group.
Here is the program again, with a blank for a transformation.
If the Group's rotation is set to (say) 30 degrees,
this is applied to all the children of the Group when it is rendered.
The rotation is around the center.
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 );
// Make a circle
double radius = size/6.0;
Circle leftBell = new Circle( centerX-size/2, centerY, radius, Color.DARKSLATEGREY);
bb.getChildren().add( leftBell );
// Make another circle
Circle rightBell = new Circle( centerX+size/2, centerY, radius, Color.DARKSLATEGREY);
bb.getChildren().add( rightBell );
// Rotate the entire 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 Rotated 30 degrees");
stage.setScene(scene);
stage.show();
}
}
Here is the picture it produces:
But that blank needs to be filled.