You are getting a class cast exception because you can only go up the inheritance tree. Meaning YinYang is a Shape but a Shape isnt necessarily a YinYang. createTransformedShape is returning a Path2D which is a Shape. But that Shape is not a YinYang.
You could either keep the variable yinYang = new Area(); inside your YinYang class or make your YinYang extend the area.
So intead of YinYang -> has an Area. It would be YinYang -> is an Area
If you really need to leave the extends inheritance open you can implement a shape and implement all the methods to go to the yinYang variable.
Then make a constructor like the following
private class YinYang extends Area {
public YinYang(Shape shape) {
super(shape);
}
}
public Shape moveToAndRotate(double x, double y, double theta)
{
double cx = getBounds2D().getCenterX();
double cy = getBounds2D().getCenterY();
at.translate(cx, cy);
at.translate(x, y);
at.rotate(Math.toRadians(theta));
at.translate(-cx, -cy);
return at.createTransformedShape(yingYang);
}
YingYang shape = new YingYang(shape.moveToAndRotate(newLoc1.x, newLoc1.y, theta));