JavaFX-MouseEvents将形状从圆形转换为矩形

JavaFX-MouseEvents将形状从圆形转换为矩形,java,javafx,Java,Javafx,我一直在尝试将netbeans上预先制作的名为MouseEvents shape的程序从圆形转换为矩形。我试过了,但这里有一条红线: private Rectangle createRectangle(final String name, final Color color, int width, int height) { //create a rectangle with desired name, color and radius final Rectangle rec

我一直在尝试将netbeans上预先制作的名为MouseEvents shape的程序从圆形转换为矩形。我试过了,但这里有一条红线:

 private Rectangle createRectangle(final String name, final Color color, int width, int height) {
    //create a rectangle with desired name,  color and radius
    final Rectangle rectangle = new Rectangle(width, new RadialGradient(0, 0, 0.2, 0.3, 1, true, CycleMethod.NO_CYCLE, new Stop[] {
        new Stop(0, Color.rgb(250,250,255)),
        new Stop(1, color)
    }));
下面是另一段代码,可以帮助您回答:

 final Rectangle rectangleSmall = createRectangle("Blue rectangle", Color.DODGERBLUE, 25,10);

首先,不清楚是将圆转换为矩形,还是将圆转换为矩形,以及“转换”是什么意思

而且,您根本没有创建矩形,因为您根本没有使用height变量。请尝试以下方法:

final Rectangle rectangle = new Rectangle(width, height, new RadialGradient(0, 0, 0.2, 0.3, 1, true, CycleMethod.NO_CYCLE, new Stop[] {
        new Stop(0, Color.rgb(250,250,255)),
        new Stop(1, color)
    });

不清楚你想要什么,你遇到了什么问题。@MDMuziburRahman我在新的径向梯度下得到了一条红线(0,0,0.2,0.3,1,true,CycleMethod.NO_CYCLE,new Stop[]{new Stop(0,Color.rgb(250250255)),new Stop(1,Color)})); 它说不兼容类型:Radialgradient无法转换为doublewell,可能是因为您根本没有使用“height”变量。