I have managed to get 2 buttons working using an if and else statement. if i add another if/else statement the program no longer works. How can i add more statements so that other buttons in my GUI work? I have about 7 more buttons to code
package finalgui;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
public class FXMLDocumentController{
@FXML
private Button btnViewSPC;
@FXML
private Button btnBack;
@FXML
private void handleButtonAction(ActionEvent event) throws IOException{
Stage stage;
Parent root;
if(event.getSource()==btnViewSPC) {
//get reference to the button's stage
stage=(Stage) btnViewSPC.getScene().getWindow();
//load up next scene
root = FXMLLoader.load(getClass().getResource("addviewdel.fxml"));
}
else{
stage=(Stage) btnBack.getScene().getWindow();
root = FXMLLoader.load(getClass().getResource("FinalGUI.fxml"));
}
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
Aucun commentaire:
Enregistrer un commentaire