我正在使用javaFX场景构建器,我创建了一个界面并在其上放置按钮,但是当我按下一个按钮时,它有一个方法可以打印" Hello"例如,在我第一次按它之后,它什么也没做,在第二次按下之后它按方法执行2次(它打印Hello 2次),之后它工作得很好,但这发生在我的界面上的一切,我必须按下所有按钮2次,我必须将东西悬停2次以便它可以工作,我不知道为什么,能不能帮助我吗?
这是我的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>
我的控制器类
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!!!");
});
}
}
我的申请类
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);
}
}
按下bFwd后,蓝点移动2倍于输出所示的距离,其原始(x)坐标为484(起始x坐标),从1点击进入519.5然后到555.0它应该在第二次点击后转到555.0然后它正常(在x坐标上点击35.5单位)抱歉我不能发布图像我有5个代表,需要10个声誉。
答案 0 :(得分:0)
您描述的问题是由您的处理程序方法引起的。 FXMLLoader
的工作方式是它在控件上注册一个处理程序,它调用你指定的方法。
所以
<Button fx:id="bBack" ... onMouseClicked="#setDateBack" ... />
导致FXMLLoader
使用调用bBack
方法的setDateBack(...)
注册处理程序(对于鼠标单击事件)。这样做的结果是当您在bBack
按钮上单击鼠标时,将调用setDateBack(...)
方法。
但是你对该方法的实现并没有直接执行你想要执行的代码:它只是在按钮上设置另一个处理程序。因此,当您第一次单击按钮上的鼠标时,您的方法会在按钮上设置处理程序。第二次单击该按钮时,将调用第二个处理程序来执行其中的代码。 (由于您使用了setOnMouseClicked(...)
方法,因此第二个处理程序将替换第一个。)
你只想要
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());
}
}
就像说明一样,代码中还有许多其他错误(大部分FXML定义的控件都没有注释,有些控件是reinitialized in your controller,你在按钮上使用鼠标监听器而不是处理动作事件:可能有其他人)。我刚刚解决了你问过的问题。最好是创建minimal example以便隔离每个错误。 (另外,请发布可执行文件示例。没有人可以运行您的代码,因为您引用了所有这些图像,并且图像与问题无关。)