为什么这个Java程序的滑块不工作?

为什么这个Java程序的滑块不工作?,java,javafx,slider,Java,Javafx,Slider,这是一个风扇程序,其中使用滑块来增加和降低风扇的速度。我不需要增加和减少按钮,我只有他们作为一个指南,以帮助滑块计算出发生了什么,当你向左或向右滚动。我稍后会删除这些内容。我的滑块没有显示,无法测试。我哪里出了问题 import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.application.Application; import javafx.geometry.Insets; impo

这是一个风扇程序,其中使用滑块来增加和降低风扇的速度。我不需要增加和减少按钮,我只有他们作为一个指南,以帮助滑块计算出发生了什么,当你向左或向右滚动。我稍后会删除这些内容。我的滑块没有显示,无法测试。我哪里出了问题

import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import javafx.util.Duration;
import javafx.scene.control.Slider;


public class module2 extends Application {

   @Override
    public void start(Stage primaryStage) throws Exception {

        // Create fan pane
        FanPane fanPane = new FanPane(100);

        Slider mSlider = new Slider();
        HBox scrollPane = new HBox(mSlider);

        KeyFrame keyFrame = new KeyFrame(Duration.millis(10), e-> fanPane.spin());

        Timeline fanTimeline = new Timeline(keyFrame);
        fanTimeline.setCycleCount(Timeline.INDEFINITE);

        // Buttons pause, resume, increase, decrease, reverse
        Button pause = new Button("Pause");
        pause.setOnAction(e-> fanTimeline.pause());

        Button resume = new Button("Resume");
        resume.setOnAction(e-> fanTimeline.play());

        //fanPane.increase()
        Button increase = new Button("Increase");
        increase.setOnAction(e -> {
            fanTimeline.setRate(fanTimeline.getCurrentRate() + 1);
            mSlider.setValue(fanTimeline.getCurrentRate());
        });

        Button decrease = new Button("Decrease");
        decrease.setOnAction(e -> {
            fanTimeline.setRate(
                    (fanTimeline.getCurrentRate() - 1 < 0) ? 0 : fanTimeline.getCurrentRate() - 1);
            mSlider.setValue(fanTimeline.getCurrentRate());

        });

        Button reverse = new Button("Reverse");
        reverse.setOnAction(e-> fanPane.increment *= -1);
        HBox hButtons = new HBox(pause,resume,reverse);
        hButtons.setSpacing(10);
        hButtons.setAlignment(Pos.CENTER);
        hButtons.setPadding(new Insets(10, 10, 10, 10));
        BorderPane borderPane = new BorderPane(fanPane, null, null, hButtons, null);







        primaryStage.setScene(new Scene(borderPane));
        primaryStage.setTitle("Spinning fan");
        primaryStage.show();
    }

    public static void main(String[] args) {
        Application.launch(args);
    }

    private class FanPane extends Pane {

        private Circle c;
        private Arc[] blades = new Arc[4];
        private double increment = 1;




        Slider mSlider = new Slider();
        HBox scrollPane = new HBox(mSlider);


        FanPane(double radius) {
            setMinHeight(400);
            setMinWidth(400);
            c = new Circle(200,200,radius,Color.BLUE);
            c.setStroke(Color.BLACK);

            double bladeRadius = radius * 0.9;
            for (int i = 0; i < blades.length; i++) {
                blades[i] = new Arc(
                        c.getCenterX(), c.getCenterY(), // center point
                        bladeRadius, bladeRadius, // X and Y radius
                        (i * 90) + 30, 35); // start angle and length
                blades[i].setFill(Color.YELLOW);
                blades[i].setType(ArcType.ROUND);
            }

            getChildren().addAll(c);
            getChildren().addAll(blades);


        }



        private void spin() {
            for (Arc blade : blades) {
                double prevStartAngle = blade.getStartAngle();
                blade.setStartAngle(prevStartAngle + increment);
            }
        }

    }
}
导入javafx.animation.KeyFrame;
导入javafx.animation.Timeline;
导入javafx.application.application;
导入javafx.geometry.Insets;
导入javafx.geometry.Pos;
导入javafx.scene.scene;
导入javafx.scene.control.Button;
导入javafx.scene.layout.BorderPane;
导入javafx.scene.layout.HBox;
导入javafx.scene.layout.Pane;
导入javafx.scene.paint.Color;
导入javafx.scene.shape.Arc;
导入javafx.scene.shape.ArcType;
导入javafx.scene.shape.Circle;
导入javafx.stage.stage;
导入javafx.util.Duration;
导入javafx.scene.control.Slider;
公共类模块2扩展了应用程序{
@凌驾
public void start(Stage primaryStage)引发异常{
//创建风扇窗格
扇形窗格扇形窗格=新扇形窗格(100);
滑块mSlider=新滑块();
HBox滚动窗格=新的HBox(mSlider);
KeyFrame KeyFrame=新的关键帧(Duration.millis(10),e->fanPane.spin());
时间线=新时间线(关键帧);
fanTimeline.setCycleCount(Timeline.unfinite);
//按钮暂停、恢复、增加、减少、反转
按钮暂停=新按钮(“暂停”);
pause.setOnAction(e->fanTimeline.pause());
按钮恢复=新按钮(“恢复”);
resume.setOnAction(e->fantaline.play());
//fanPane.increase()
按钮增加=新按钮(“增加”);
增加设定动作(e->{
fanTimeline.setRate(fanTimeline.getCurrentRate()+1);
mSlider.setValue(fanTimeline.getCurrentRate());
});
按钮减少=新按钮(“减少”);
减少设定动作(e->{
设定值(
(fanTimeline.getCurrentRate()-1<0)?0:fanTimeline.getCurrentRate()-1);
mSlider.setValue(fanTimeline.getCurrentRate());
});
按钮反转=新按钮(“反转”);
反转.setOnAction(e->fanPane.increment*=-1);
HBox按钮=新HBox(暂停、恢复、反转);
hButtons.setspace(10);
H按钮设置对齐(位置中心);
hButtons.设置填充(新的插图(10,10,10,10));
BorderPane BorderPane=新的BorderPane(扇形窗格,null,null,hButtons,null);
primaryStage.setScene(新场景(边框窗格));
初级阶段。片名(“旋转风扇”);
primaryStage.show();
}
公共静态void main(字符串[]args){
应用程序启动(args);
}
私有类窗格扩展窗格{
私人圈子c;
专用弧[]刀片=新弧[4];
私人双增量=1;
滑块mSlider=新滑块();
HBox滚动窗格=新的HBox(mSlider);
扇形窗格玻璃(双半径){
设置最小高度(400);
设置最小宽度(400);
c=新圆(200200,半径,颜色。蓝色);
c、 设定行程(颜色为黑色);
双叶片=半径*0.9;
对于(int i=0;i
请发布一条消息,说明您没有将
滚动窗格添加到场景的任何位置。。。