当我按下其他班级的按钮时如何显示图像(1级)

时间:2019-06-01 09:45:44

标签: javafx scenebuilder

(我真的是java和javafx的初学者)

当我在一个场景(class2)中时,我按下“ Guardar”按钮,我需要返回另一个场景(class1)并显示图像(双票)(https://ibb.co/2jjJ5j3)。

我已经有3个场景了。

我的问题是,当我在其他场景中按“ Guardar”时,它会重新显示并显示正确的doubleTicket图像,但是与该另一场景的另一个按钮相对应显示的图像消失了。

我知道我的解释可能会造成混淆,不是我的语言或我的代码语言,但是我将附加代码以更好地理解。

这是我的代码:

公共类Vista1Controller {(在该类中,如果我在“ Formulario1”类中按了“ Guardar”,则需要显示图像)

@FXML private ImageView doubleTicket1;
@FXML private ImageView doubleTicket2;
@FXML private ImageView doubleTicket3;


public void onImagetuerca1PressedChangeScene(MouseEvent event) throws IOException {
    Parent vista1parent = FXMLLoader.load(getClass().getResource("/formulario1.fxml"));
    Scene vista1Scene = new Scene(vista1parent);

    Stage window = (Stage) ((Node) event.getSource()) .getScene() .getWindow();
    window.setScene(vista1Scene);
    window.show();
}

public void onImagetuerca2PressedChangeScene(MouseEvent event) throws IOException {
    Parent vista2parent = FXMLLoader.load(getClass().getResource("/formulario2.fxml"));
    Scene vista2Scene = new Scene(vista2parent);

    Stage window = (Stage) ((Node) event.getSource()) .getScene() .getWindow();
    window.setScene(vista2Scene);
    window.show();
}

public void onImagetuerca3PressedChangeScene(MouseEvent event) throws IOException {
    Parent vista3parent = FXMLLoader.load(getClass().getResource("/formulario3.fxml"));
    Scene vista3Scene = new Scene(vista3parent);

    Stage window = (Stage) ((Node) event.getSource()) .getScene() .getWindow();
    window.setScene(vista3Scene);
    window.show();
}

public void setDoubleTicket1Visible(boolean e){
    doubleTicket1.setVisible(e);
}

public void setDoubleTicket2Visible(){
    if(doubleTicket1.isVisible()){
        doubleTicket1.setVisible(true);
        return;
    }
    doubleTicket2.setVisible(true);
}

public void setDoubleTicket3Visible(){
    doubleTicket3.setVisible(true);
}

公共类Formulario1Controller {

public void changeSceneOnButtonGuardarPressedF1(ActionEvent event) throws IOException{

    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(getClass().getResource("/vista1.fxml"));
    Parent buttonparent = loader.load();
    Scene buttonScene = new Scene(buttonparent);


    Vista1Controller vista1Controller = loader.getController();
    vista1Controller.setDoubleTicket1Visible(true);


    Stage window = (Stage) ((Node) event.getSource()) .getScene() .getWindow();
    window.setScene(buttonScene);
    window.show();



}

public void changeSceneOnButtonVolverPressedF1(ActionEvent event) throws IOException{

    Parent buttonparent = FXMLLoader.load(getClass().getResource("/vista1.fxml"));
    Scene buttonScene = new Scene(buttonparent);

    Stage window = (Stage) ((Node) event.getSource()) .getScene() .getWindow();
    window.setScene(buttonScene);
    window.show();
}

公共类Formulario2Controller扩展了Formulario1Controller { (当此处显示图像时,Formulario1的图像消失了)

public void changeSceneOnButtonGuardarPressedF2(ActionEvent event) throws IOException {

    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(getClass().getResource("/vista1.fxml"));
    Parent buttonparent = loader.load();
    Scene buttonScene = new Scene(buttonparent);

    Vista1Controller vista1Controller = loader.getController();
    vista1Controller.setDoubleTicket2Visible();


    Stage window = (Stage) ((Node) event.getSource()) .getScene() .getWindow();
    window.setScene(buttonScene);
    window.show();



}

public void changeSceneOnButtonVolverPressedF2(ActionEvent event) throws IOException{

    Parent buttonparent = FXMLLoader.load(getClass().getResource("/vista1.fxml"));
    Scene buttonScene = new Scene(buttonparent);

    Stage window = (Stage) ((Node) event.getSource()) .getScene() .getWindow();
    window.setScene(buttonScene);
    window.show();

}

简而言之,我需要在出现Formulario2的图像时仍可以看到Formulario1的图像

我在班级之间的交流方面遇到严重问题

谢谢!

0 个答案:

没有答案