0

I am working with javaFX scene builder, I made a interface and put buttons on it, but when I press a button which has a method that prints "Hello" for example, after I press it the first time, it does nothing, after the second press it does the method 2 times (it prints Hello 2 times), after this it works just fine, but this happens to everything on my interface, I have to push all buttons 2 times, I have to hover something 2 times so it works and I don't know why, can anyone help me please?

This is my FXML

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.shape.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.chart.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane fx:id="aPane" centerShape="false" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1280.0" scaleShape="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.MyController">
   <effect>
      <Blend />
   </effect>
   <children>
      <Pane fx:id="secPane" prefHeight="800.0" prefWidth="1280.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
         <children>
            <ComboBox fx:id="ora" layoutX="14.0" layoutY="217.0" prefHeight="25.0" prefWidth="174.0" promptText="Selectati ora" visible="false" />
            <DatePicker fx:id="data" layoutX="14.0" layoutY="127.0" promptText="Selectati data" />
            <Pane fx:id="imgPane" layoutX="200.0" layoutY="14.0" prefHeight="692.0" prefWidth="1066.0" style="-fx-background-color: black;">
               <children>
                  <ImageView fx:id="sMap" fitHeight="692.0" fitWidth="1066.0" layoutX="-1.0" pickOnBounds="true" preserveRatio="true" />
                  <ImageView fx:id="Sirius" fitHeight="11.0" fitWidth="10.0" layoutX="484.0" layoutY="434.0" onMouseEntered="#mouseEnteredSirius" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@../../Img/sirius.png" />
                     </image>
                  </ImageView>
                  <ImageView fx:id="Procyon" fitHeight="8.0" fitWidth="7.0" layoutX="433.0" layoutY="320.0" onMouseEntered="#mouseEnteredProcyon" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@../../Img/procyon.png" />
                     </image>
                  </ImageView>
                  <ImageView fx:id="Beetlegeuse" fitHeight="9.0" fitWidth="9.0" layoutX="551.0" layoutY="320.0" onMouseEntered="#mouseEnteredBeetlegeuse" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@../../Img/beetlegeuse.png" />
                     </image>
                  </ImageView>
                  <ImageView fx:id="Rigel" fitHeight="8.0" fitWidth="9.0" layoutX="599.0" layoutY="399.0" onMouseEntered="#mouseEnteredRigel" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@../../Img/rigel.png" />
                     </image></ImageView>
                  <ImageView fx:id="Capella" fitHeight="12.0" fitWidth="11.0" layoutX="598.0" layoutY="127.0" onMouseEntered="#mouseEnteredCapella" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@../../Img/capella.png" />
                     </image>
                  </ImageView>
                  <ImageView fx:id="Aldebaran" fitHeight="6.0" fitWidth="7.0" layoutX="646.0" layoutY="282.0" onMouseEntered="#mouseEnteredAldebaran" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@../../Img/aldebaran.png" />
                     </image>
                  </ImageView>
                  <ImageView fx:id="Polux" fitHeight="6.0" fitWidth="7.0" layoutX="446.0" layoutY="214.0" onMouseEntered="#mouseEnteredPolux" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@../../Img/polux.png" />
                     </image>
                  </ImageView>
                  <ImageView fx:id="Castor" fitHeight="4.0" fitWidth="3.0" layoutX="463.0" layoutY="200.0" onMouseEntered="#mouseEnteredCastor" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@../../Img/castor.png" />
                     </image>
                  </ImageView>
                  <ImageView fx:id="Regulus" fitHeight="4.0" fitWidth="4.0" layoutX="163.0" layoutY="230.0" onMouseEntered="#mouseEnteredRegulus" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@../../Img/regulus.png" />
                     </image>
                  </ImageView>
                  <ImageView fx:id="Mirphak" fitHeight="5.0" fitWidth="5.0" layoutX="728.0" layoutY="55.0" onMouseEntered="#mouseEnteredMirphak" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@../../Img/mirphak.png" />
                     </image>
                  </ImageView>
                  <Label layoutX="511.0" layoutY="6.0" prefHeight="35.0" prefWidth="35.0" text=" N" textAlignment="JUSTIFY" textFill="#fc0f0f">
                     <font>
                        <Font name="System Bold" size="22.0" />
                     </font>
                  </Label>
                  <Label layoutX="508.0" layoutY="643.0" prefHeight="35.0" prefWidth="35.0" text="  S" textFill="#fc0f0f">
                     <font>
                        <Font name="System Bold" size="22.0" />
                     </font>
                  </Label>
                  <Label layoutX="14.0" layoutY="338.0" prefHeight="35.0" prefWidth="35.0" text=" W" textFill="#fc0f0f">
                     <font>
                        <Font name="System Bold" size="22.0" />
                     </font>
                  </Label>
                  <Label layoutX="1017.0" layoutY="329.0" prefHeight="35.0" prefWidth="35.0" text="  E" textFill="#fc0f0f">
                     <font>
                        <Font name="System Bold" size="22.0" />
                     </font>
                  </Label>
                  <ImageView fx:id="debug" fitHeight="5.0" fitWidth="5.0" layoutX="487.0" layoutY="438.0" pickOnBounds="true" preserveRatio="true" visible="false">
                     <image>
                        <Image url="@../../Img/red.png" />
                     </image>
                  </ImageView>
                  <ImageView fx:id="nodePos1" disable="true" fitHeight="15.0" fitWidth="15.0" layoutX="1027.0" layoutY="653.0" pickOnBounds="true" preserveRatio="true" visible="false">
                     <image>
                        <Image url="@../../Img/halo.png" />
                     </image>
                  </ImageView>
                  <ImageView fx:id="nodePos2" disable="true" fitHeight="15.0" fitWidth="15.0" layoutX="964.0" layoutY="658.0" pickOnBounds="true" preserveRatio="true" visible="false">
                     <image>
                        <Image url="@../../Img/halo.png" />
                     </image>
                  </ImageView>
                  <ImageView fx:id="nodePos3" disable="true" fitHeight="15.0" fitWidth="15.0" layoutX="1010.0" layoutY="636.0" pickOnBounds="true" preserveRatio="true" visible="false">
                     <image>
                        <Image url="@../../Img/halo.png" />
                     </image>
                  </ImageView>
                  <ImageView fx:id="nodePos4" disable="true" fitHeight="15.0" fitWidth="15.0" layoutX="794.0" layoutY="494.0" pickOnBounds="true" preserveRatio="true" visible="false">
                     <image>
                        <Image url="@../../Img/halo.png" />
                     </image>
                  </ImageView>
                  <ImageView fx:id="nodePos5" disable="true" fitHeight="15.0" fitWidth="15.0" layoutX="233.0" layoutY="419.0" pickOnBounds="true" preserveRatio="true" visible="false">
                     <image>
                        <Image url="@../../Img/halo.png" />
                     </image>
                  </ImageView>
                  <ImageView fx:id="nodePos6" disable="true" fitHeight="15.0" fitWidth="15.0" layoutX="84.0" layoutY="434.0" pickOnBounds="true" preserveRatio="true" visible="false">
                     <image>
                        <Image url="@../../Img/halo.png" />
                     </image>
                  </ImageView>
                  <ImageView fx:id="nodePos7" disable="true" fitHeight="15.0" fitWidth="15.0" layoutX="84.0" layoutY="434.0" pickOnBounds="true" preserveRatio="true" visible="false">
                     <image>
                        <Image url="@../../Img/halo.png" />
                     </image>
                  </ImageView>
                  <ImageView fx:id="infoSirius" fitHeight="100.0" fitWidth="100.0" layoutX="14.0" layoutY="578.0" pickOnBounds="true" preserveRatio="true" visible="false">
                     <image>
                        <Image url="@../../Img/blueStar.gif" />
                     </image>
                  </ImageView>
                  <Label fx:id="sName1" contentDisplay="CENTER" layoutX="14.0" layoutY="541.0" lineSpacing="5.0" prefHeight="25.0" prefWidth="100.0" text="Sirius" textAlignment="JUSTIFY" textFill="#0d09e1" underline="true" visible="false">
                     <font>
                        <Font name="System Bold" size="20.0" />
                     </font>
                  </Label>
                  <ImageView fx:id="infoBetlegeuse" fitHeight="100.0" fitWidth="100.0" layoutX="113.0" layoutY="578.0" pickOnBounds="true" preserveRatio="true" visible="false">
                     <image>
                        <Image url="@../../Img/redStar.gif" />
                     </image>
                  </ImageView>
                  <Label fx:id="sName2" layoutX="115.0" layoutY="541.0" prefHeight="30.0" prefWidth="100.0" text="Betlegeuse" textFill="#c90805" underline="true" visible="false">
                     <font>
                        <Font name="System Bold" size="19.0" />
                     </font>
                  </Label>
               </children></Pane>
            <Button fx:id="bInfo" layoutX="14.0" layoutY="401.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="174.0" text="Informatii" />
            <Button fx:id="bHelp" layoutX="14.0" layoutY="470.0" mnemonicParsing="false" prefHeight="42.0" prefWidth="59.0" text="Help" />
            <ImageView fx:id="logo" fitHeight="79.0" fitWidth="174.0" layoutX="14.0" layoutY="5.0" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@../../Img/SM.jpg" />
               </image></ImageView>
            <Button fx:id="bBack" layoutX="291.0" layoutY="717.0" mnemonicParsing="false" onMouseClicked="#setDateBack" prefHeight="42.0" prefWidth="79.0" text="Inapoi" />
            <Button fx:id="bFwd" layoutX="1075.0" layoutY="716.0" mnemonicParsing="false" onMousePressed="#setDateFwd" prefHeight="42.0" prefWidth="79.0" text="Inainte" />
            <Label fx:id="titluData" layoutX="50.0" layoutY="90.0" prefHeight="25.0" prefWidth="86.0" text="Data">
               <font>
                  <Font name="System Bold" size="18.0" />
               </font>
            </Label>
            <Label fx:id="titluOra" layoutX="50.0" layoutY="179.0" prefHeight="25.0" prefWidth="86.0" text="Ora" visible="false">
               <font>
                  <Font name="System Bold" size="18.0" />
               </font>
            </Label>
            <Label fx:id="sDate" layoutX="710.0" layoutY="716.0" prefHeight="35.0" prefWidth="184.0" text="Data">
               <font>
                  <Font name="System Bold" size="15.0" />
               </font></Label>
            <Label fx:id="pData" layoutX="572.0" layoutY="720.0" prefHeight="27.0" prefWidth="138.0" text="Data selectata :">
               <font>
                  <Font name="System Bold" size="15.0" />
               </font>
            </Label>
            <Label fx:id="pOra" layoutX="572.0" layoutY="741.0" prefHeight="35.0" prefWidth="138.0" text="Ora selectata :">
               <font>
                  <Font name="System Bold" size="15.0" />
               </font>
            </Label>
            <Label fx:id="labelOra" layoutX="710.0" layoutY="746.0" prefHeight="27.0" prefWidth="138.0" text="Ora">
               <font>
                  <Font name="System Bold" size="15.0" />
               </font>
            </Label>
            <Button fx:id="bAf" layoutX="14.0" layoutY="270.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="174.0" text="Afis" />
         </children>
      </Pane>
   </children>
</AnchorPane>

My Controller class

package controller;

import java.net.URL;
import java.time.LocalDate;
import java.util.ResourceBundle;

import javafx.animation.FadeTransition;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.animation.TranslateTransition;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.util.Duration;
import Effects.ZoomIn;
import Effects.ZoomOut;

public class MyController implements Initializable {

    @Override
    public void initialize(URL arg0, ResourceBundle arg1) {

        ora.setItems(listaOra);
        ora.show();
        sDate.setText("2014-08-15");
        labelOra.setText("23:00");

    }

    @FXML
    public Button bAf;
    public Button bBack;
    public Button bFwd;

    public DatePicker data = new DatePicker();
    public Label sDate;
    public Label labelOra, sName1, sName2;
    public ComboBox<String> ora = new ComboBox();
    Timeline forward = new Timeline();

    Node node;

    public ImageView Mirphak, Sirius, Castor, Polux, Procyon, Beetlegeuse,
            Rigel, Aldebaran, Capella, Regulus, infoSirius, nodePos1, nodePos2,
            nodePos3, nodePos4, nodePos5, nodePos6, nodePos7, sName, infoBetlegeuse;

    public LocalDate ld;
    TranslateTransition tTrans;

    ObservableList<String> listaOra = FXCollections.observableArrayList(

    "23:00", "23:30", "00:00", "00:30", "01:00", "01:30", "02:00", "02:30",
            "03:00", "03:30", "04:00", "04:30", "05:00", "05:30", "06:00",
            "06:30", "07:00"

    );

    public KeyFrame makeKeyFrame(int sec, double xVal, double yVal) {

        return new KeyFrame(

        new Duration(sec), new KeyValue(node.translateXProperty(), xVal),
                new KeyValue(node.translateYProperty(), yVal));
    }

    public void infoFadeInSirius(Node node) {

        if (!node.isVisible()) {

            node.setVisible(true);

        }

        FadeTransition fadeIn = new FadeTransition(Duration.millis(1500));

        fadeIn.setNode(node);

        fadeIn.setFromValue(0.0);
        fadeIn.setToValue(1.0);

        fadeIn.play();

    }

        FadeTransition fadeIn = new FadeTransition(Duration.millis(1500));

        fadeIn.setNode(node);

        fadeIn.setFromValue(0.0);
        fadeIn.setToValue(1.0);

        fadeIn.play();

    }

    public void infoFadeInSiriusLbl(Node node) {

        if (!node.isVisible()) {

            node.setVisible(true);

        }

        FadeTransition fadeIn = new FadeTransition(Duration.millis(1500));

        fadeIn.setNode(node);

        fadeIn.setFromValue(0.0);
        fadeIn.setToValue(1.0);

        fadeIn.play();
    }
public void infoFadeOutSirius(Node node) {

        FadeTransition fadeOut = new FadeTransition(Duration.millis(1500));

        fadeOut.setNode(node);

        fadeOut.setFromValue(1.0);
        fadeOut.setToValue(0.0);

        fadeOut.play();
        if (node.getOpacity() == 0.0) {
            node.setVisible(false);
        }

    }

public void infoFadeOutSiriusLbl(Node node) {

        FadeTransition fadeOut = new FadeTransition(Duration.millis(1500));

        fadeOut.setNode(node);

        fadeOut.setFromValue(1.0);
        fadeOut.setToValue(0.0);

        fadeOut.play();
        if (node.getOpacity() == 0.0) {
            node.setVisible(false);
        }

    }
    public void infoFadeOutBetlegeuseLbl(Node node) {

        FadeTransition fadeOut = new FadeTransition(Duration.millis(1500));

        fadeOut.setNode(node);

        fadeOut.setFromValue(1.0);
        fadeOut.setToValue(0.0);

        fadeOut.play();
        if (node.getOpacity() == 0.0) {
            node.setVisible(false);
        }
    }

    public void sky(Node node, double xDest, double yDest) {

        TranslateTransition tTrans = new TranslateTransition(
                Duration.millis(4000), node);

        tTrans.setFromX(0);

        tTrans.setToX(xDest);

        tTrans.setFromY(0);

        tTrans.setToY(yDest);
       

        node.setLayoutX(node.getLayoutX() + xDest);
        node.setLayoutY(node.getLayoutY() + yDest);
        tTrans.setRate(2);
        tTrans.setInterpolator(Interpolator.LINEAR);

       
        tTrans.play();

    }

    public void moveNode(Node node) {

    }

    public void rewindSky(Node node, double xDest, double yDest) {

        TranslateTransition tTrans = new TranslateTransition(
                Duration.seconds(4), node);

        tTrans.setFromX(0);
        tTrans.setToX(xDest);
        tTrans.setRate(2);
        tTrans.setInterpolator(Interpolator.LINEAR);

        tTrans.setFromY(0);
        tTrans.setToY(yDest);
        tTrans.setRate(2);
        tTrans.setInterpolator(Interpolator.LINEAR);

        node.setLayoutX(node.getLayoutX() + xDest);
        node.setLayoutY(node.getLayoutY() + yDest);
        tTrans.play();
    }

    public void followNode(Node node, double xDest, double yDest) {

        if (!nodePos1.isVisible()) {

            tTrans.stop();
        }

        TranslateTransition tTrans = new TranslateTransition(
                Duration.seconds(5), node);

        tTrans.getByX();
        tTrans.setToX(xDest);
        tTrans.setRate(2);
        tTrans.setInterpolator(Interpolator.LINEAR);

        tTrans.getByY();
        tTrans.setToY(yDest);
        tTrans.setRate(2);
        tTrans.setInterpolator(Interpolator.LINEAR);

        node.getLayoutX();
        node.getLayoutY();

        tTrans.play();

    }

    public void splitStar(Node node) {

        if (!nodePos1.isVisible()) {

            nodePos1.setVisible(true);
            nodePos2.setVisible(true);
            nodePos3.setVisible(true);
            nodePos4.setVisible(true);
            nodePos5.setVisible(true);
            nodePos6.setVisible(true);
            nodePos7.setVisible(true);

            nodePos1.setLayoutX(node.getLayoutX());
            nodePos1.setLayoutY(node.getLayoutY());

            nodePos2.setLayoutX(node.getLayoutX());
            nodePos2.setLayoutY(node.getLayoutY());

            nodePos3.setLayoutX(node.getLayoutX());
            nodePos3.setLayoutY(node.getLayoutY());

            nodePos4.setLayoutX(node.getLayoutX());
            nodePos4.setLayoutY(node.getLayoutY());

            nodePos5.setLayoutX(node.getLayoutX());
            nodePos5.setLayoutY(node.getLayoutY());

            nodePos6.setLayoutX(node.getLayoutX());
            nodePos6.setLayoutY(node.getLayoutY());

            nodePos7.setLayoutX(node.getLayoutX());
            nodePos7.setLayoutY(node.getLayoutY());

            followNode(nodePos1, 35.5, 4.5);
            followNode(nodePos2, 35.5 * 2, 4.5 * 2);
            followNode(nodePos6, 35.5 * 3, 4.5 * 3);
            followNode(nodePos5, 0, 0);
            followNode(nodePos3, -35.5, -4.5);
            followNode(nodePos4, -35.5 * 2, -4.5 * 2);
            followNode(nodePos7, 35.5 * 4, 4.5 * 4);

        }

    }

    public void splitStarFalse(Node node) {

        nodePos1.setVisible(false);
        nodePos2.setVisible(false);
        nodePos3.setVisible(false);
        nodePos4.setVisible(false);
        nodePos5.setVisible(false);
        nodePos6.setVisible(false);
        nodePos7.setVisible(false);

        nodePos1.setTranslateX(0);
        nodePos2.setTranslateX(0);
        nodePos3.setTranslateX(0);
        nodePos4.setTranslateX(0);
        nodePos5.setTranslateX(0);
        nodePos6.setTranslateX(0);
        nodePos7.setTranslateX(0);

        nodePos1.setTranslateY(0);
        nodePos2.setTranslateY(0);
        nodePos3.setTranslateY(0);
        nodePos4.setTranslateY(0);
        nodePos5.setTranslateY(0);
        nodePos6.setTranslateY(0);
        nodePos7.setTranslateY(0);

    }

    public void setDateFwd(MouseEvent event) {

        

        bFwd.setOnMousePressed(e -> {

            if (data.getValue() == null) {
                System.out.println("Introduceti data!!!");
            }
            double x = 35.5;
            double y = 4.5;

            if (data.getValue().equals(LocalDate.of(2014, 8, 15))
                    && labelOra.getText().equals("23:00") == true) {

                ld = data.getValue();

                System.out.println("" + ld);
                sDate.setText(ld.toString());

                System.out.println("" + listaOra.get(1).toString());
                labelOra.setText(listaOra.get(1).toString());

                sky(Sirius, x, y);
                sky(Procyon, 35.5, 4.5);
                sky(Beetlegeuse, 35.5, 4.5);
                sky(Polux, 35.5, 4.5);
                sky(Capella, 35.5, 4.5);
                sky(Regulus, 35.5, 4.5);
                sky(Rigel, 35.5, 4.5);
                sky(Aldebaran, 35.5, 4.5);
                sky(Castor, 35.5, 4.5);
                sky(Mirphak, 35.5, 4.5);

                System.out.println("" + Sirius.getLayoutX());
                Sirius.getLayoutY();
            }

            if (data.getValue().equals(LocalDate.of(2014, 8, 15))
                    && labelOra.getText().equals("23:30") == true) {

                sky(Sirius, x, y);
                sky(Procyon, 35.5, 4.5);
                sky(Beetlegeuse, 35.5, 4.5);
                sky(Polux, 35.5, 4.5);
                sky(Capella, 35.5, 4.5);
                sky(Regulus, 35.5, 4.5);
                sky(Rigel, 35.5, 4.5);
                sky(Aldebaran, 35.5, 4.5);
                sky(Castor, 35.5, 4.5);
                sky(Mirphak, 35.5, 4.5);

                System.out.println("succes");

                System.out.println("" + Sirius.getLayoutX());
                System.out.println("" + Sirius.getLayoutY());

            }

         

        });

    }

    public void setDateBack(MouseEvent event) {

        bBack.setOnMouseClicked(e -> {

            if (data.getValue() == null) {
                System.out.println("Introduceti data!!!");
            }

            if (data.getValue().equals(LocalDate.of(2014, 8, 15))) {

                ld = data.getValue();

                System.out.println("" + ld);
                sDate.setText(ld.toString());

                System.out.println("" + ora.getValue());
                labelOra.setText(listaOra.get(0).toString());

                rewindSky(Sirius, -35.5, -4.5);
                rewindSky(Procyon, -35.5, -4.5);
                rewindSky(Beetlegeuse, -35.5, -4.5);
                rewindSky(Polux, -35.5, -4.5);
                rewindSky(Capella, -35.5, -4.5);
                rewindSky(Regulus, -35.5, -4.5);
                rewindSky(Rigel, -35.5, -4.5);
                rewindSky(Aldebaran, -35.5, -4.5);
                rewindSky(Castor, -35.5, -4.5);
                rewindSky(Mirphak, -35.5, -4.5);

                System.out.println("" + Sirius.getLayoutX());
                System.out.println("" + Sirius.getLayoutY());
            }
        });
    }



    public void mouseEnteredSirius(MouseEvent event) {

        Sirius.setOnMouseEntered(e -> {

            new ZoomIn(Sirius, Sirius.getScaleX() * 4, Sirius.getScaleY() * 4);

            infoFadeInSirius(infoSirius);
            infoFadeInSiriusLbl(sName1);

            splitStar(Sirius);

            System.out.println("Mouse draged!!!");
        });

        Sirius.setOnMouseExited(e2 -> {

            new ZoomOut(Sirius);

            infoFadeOutSirius(infoSirius);

            infoFadeOutSiriusLbl(sName1);

            splitStarFalse(Sirius);

            System.out.println("Mouse draged out!!!");
        });

    }

}

My application class

package application;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            Parent root = FXMLLoader.load(getClass().getResource(
                    "/application/MyView.fxml"));
            Scene scene = new Scene(root);
            scene.getStylesheets().add(
                    getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();
            setUserAgentStylesheet(STYLESHEET_CASPIAN);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

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

After I press the bFwd a blue dot moves 2 times the distance it should as shown in the output its original(x) coordinate is 484 (starting x coordinate) and it goes to 519.5 then to 555.0 from 1 click and it should go to 555.0 after a second click then it goes normally (35.5 units a click on x coordinate) sorry I can't post image I have 5 rep and need 10 reputation.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38

1 Answers1

0

The issue you describe is caused by your handler method. The way the FXMLLoader works is that it registers a handler on the control which invokes the method you specify.

So

<Button fx:id="bBack" ... onMouseClicked="#setDateBack" ... />

causes the FXMLLoader to register a handler (for mouse clicked events) with the bBack that invokes the setDateBack(...) method. The effect of this is that when you click the mouse on the bBack button, your setDateBack(...) method gets called.

But your implementation of that method doesn't directly execute the code you want to execute: it merely sets another handler on the button. So the first time you click the mouse on the button, your method sets a handler on the button. The second time you click on the button, the second handler is invoked that executes the code in there. (Since you used the setOnMouseClicked(...) method, the second handler replaces the first.)

You just want

public void setDateBack(MouseEvent event) {

    if (data.getValue() == null) {
        System.out.println("Introduceti data!!!");
    }

    if (data.getValue().equals(LocalDate.of(2014, 8, 15))) {

        ld = data.getValue();

        System.out.println("" + ld);
        sDate.setText(ld.toString());

        System.out.println("" + ora.getValue());
        labelOra.setText(listaOra.get(0).toString());

        rewindSky(Sirius, -35.5, -4.5);
        rewindSky(Procyon, -35.5, -4.5);
        rewindSky(Beetlegeuse, -35.5, -4.5);
        rewindSky(Polux, -35.5, -4.5);
        rewindSky(Capella, -35.5, -4.5);
        rewindSky(Regulus, -35.5, -4.5);
        rewindSky(Rigel, -35.5, -4.5);
        rewindSky(Aldebaran, -35.5, -4.5);
        rewindSky(Castor, -35.5, -4.5);
        rewindSky(Mirphak, -35.5, -4.5);

        System.out.println("" + Sirius.getLayoutX());
        System.out.println("" + Sirius.getLayoutY());
    }
}

Just as a note, there are many other errors in your code (most of your FXML-defined controls are not annotated, some controls are reinitialized in your controller, you are using mouse listeners on buttons instead of handling action events: there are probably others). I have just addressed the one you asked about. It is better if you create a minimal example so that you can isolate each error. (Also, please post executable examples. No-one can run your code because you reference all those images, and the images are irrelevant to the problem.)

Community
  • 1
  • 1
James_D
  • 201,275
  • 16
  • 291
  • 322