I have a Controller class called: BatteryBoardSelectionFrame and I have a Controller for a javaFX scene called: CellDetailShowScene
I have 2 buttons named: redBatteryBtn and redBatteryBtn2 in "BatteryBoardSelectionFrame" class that should pass information from this class to "CellDetailShowScene" class.
I can pass redBatteryBtn information to "CellDetailShowScene" and print the informations perfect, but I don't know how to pass redBatteryBtn2 information to "CellDetailShowScene"
Every time I run the program, and click on second battery(redBatteryBtn2) it shows just first battery information(redBatteryBtn).
can you please help me with this?
The code for BatteryBoardSelectionFrame class is:
public class BatteryBoardSelectionFrame implements Initializable {
@FXML
private Button redBatteryBtn, redBatteryBtn2;
public int batteryLevel = 3;
public int batteryLevel2 = 10;
@FXML
public void openCellDetailShowScene(ActionEvent event) {
FXMLLoader loader = new FXMLLoader(getClass().getResource("View/CellDetailShowScene.fxml"));
if (event.getSource().equals(batteryLevel)) {
System.out.println("0");
try {
Parent root = (Parent) loader.load();
CellDetailShowScene cellDetailShowScene = loader.getController();
cellDetailShowScene.getCell1Data(batteryLevel);
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.show();
} catch (Exception e) {
}
}
else if(event.getSource().equals(batteryLevel2)){
System.out.println("1");
try {
Parent root = (Parent) loader.load();
CellDetailShowScene cellDetailShowScene = loader.getController();
cellDetailShowScene.getCell1Data2(batteryLevel2);
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.show();
} catch (Exception e) {
}
}
}
public int getBatteryLevel() {
return this.batteryLevel;
}
public int getBatteryLevel2() {
return this.batteryLevel;
}
}
and The code for CellDetailShowScene class is:
public class CellDetailShowScene implements Initializable {
@FXML
private Label chargeLevel;
BatteryBoardSelectionFrame batteryBoardSelectionFrame = new BatteryBoardSelectionFrame();
public void getCell1Data(int batteryLevel) {
}
public void getCell1Data2(int batteryLevel2) {
}
@Override
public void initialize(URL location, ResourceBundle resources) {
LoginFrame loginFrame= new LoginFrame();
welcomeUsername.setText("welcome " + loginFrame.getUsernameField());
int showChargeLevel1= batteryBoardSelectionFrame.getBatteryLevel2();
int showChargeLevel2= batteryBoardSelectionFrame.getBatteryLevel2();
chargeLevel.setText(String.valueOf(showChargeLevel1 + "%"));
chargeLevel.setText(String.valueOf(showChargeLevel2 + "%"));
chargeLevel.setText(String.valueOf(Integer.parseInt(String.valueOf(chargeL))));
public void getCell1Data(int chargeL, int temperatureL, int voltageL, int currentL){
int showChargeLevel= batteryBoardSelectionFrame.getBatteryLevel();
}
}
Thank you guys