从另一个类ActionEvent参数调用方法

时间:2017-12-05 10:07:03

标签: javafx netbeans

我在电梯和电梯gui上工作。 在fxmlcontroller类中,我编写了所有代码。从我们的老师那里,我们不得不把它分成多个班级。所以我做了。

移动到地板的方法现在是一个单独的类,现在是paramater ActionEvent e。我把所有东西分开了,看起来都很好。但是当我调用控制器类中的方法时(这是因为当前按钮不起作用,他们之前做过),它说它不知道变量e。我不知道如何调用这些。

这些是新课程中的方法:

public void moveToFloorZero( ActionEvent e ) {
        if ( motorDelta == 0 && motorD.getvDoor() >= 1.0 ) {
            if ( motorCage.get() < 1.0 ) {
                motorDelta = motorSpeed;
                motorC.start();
                floorIndicator = 0;
            }
        }
    }

    public void moveToFloorOne( ActionEvent e ) {
        if ( motorDelta == 0 && motorD.getvDoor() >= 1.0 ) {
            if ( motorCage.get() >= 0.0 ) {
                motorDelta = -motorSpeed;
                motorC.start();
                floorIndicator = 1;
            }
            if ( motorCage.get() < 1.0 ) {
                motorDelta = motorSpeed;
                motorC.start();
                floorIndicator = 10;
            }
        }
    }

    public void moveToFloorTwo( ActionEvent e ) {
        if ( motorDelta == 0 && motorD.getvDoor() >= 1.0 ) {
            if ( motorCage.get() > 0.66 ) {
                motorDelta = -motorSpeed;
                motorC.start();
                floorIndicator = 2;
            }
            if ( motorCage.get() <= 0.33 ) {
                motorDelta = motorSpeed;
                motorC.start();
                floorIndicator = 20;
            }
        }
    }

   public void moveToFloorThree( ActionEvent e ) {
        if ( motorDelta == 0 && motorD.getvDoor() >= 1.0 ) {
            if ( motorCage.get() >= 0.0 ) {
                motorDelta = -motorSpeed;
                motorC.start();
                floorIndicator = 3;
            }
        }
    }



    //
    //door motor imp
    class MotorDoor extends AnimationTimer {

        double vDoor = 1;

        @Override
        public void handle( long now ) {
            vDoor = motorDoor.get();
            vDoor += motorDelta;
            motorDoor.set( vDoor );
            if ( vDoor <= 0.0 || vDoor >= 1.0 ) {
                this.stop();
                motorDelta = 0;
            }
        }

        public double getvDoor() {
            return vDoor;
        }
    }

    public void openDoor( ActionEvent e ) {
        if ( motorDelta == 0 ) {
            motorDelta = -motorSpeed;
            motorD.start();
        }
    }

    public void closeDoor( ActionEvent e ) {
        if ( motorDelta == 0 ) {
            motorDelta = motorSpeed;
            motorD.start();
        }
    }

这是控制器类,我想调用这些方法:

Floor0Button.setOnAction( gm.moveToFloorZero(e));

        Floor1Button.setOnAction( gm.moveToFloorOne(e) );

        Floor2Button.setOnAction( gm.moveToFloorTwo(e) );

        Floor3Button.setOnAction( gm.moveToFloorThree(e) );

Netbeans说:创建局部变量e。说实话,我尝试了很多东西,但我无法找到解决方法。如果您需要更多信息,我可以发送给您。

亲切的问候

1 个答案:

答案 0 :(得分:0)

我不再收到错误了。但是现在,当我的GUI弹出时,按钮将无法工作。我可以点击它,但不会看到动画。如何解决这个问题?我尝试了很多东西,但是自从把所有东西分开后,这都行不通。

相关问题