I can't set Text with static. Please help me set Text for fullname and money in AccountController. Please have me and give me a few examples
I pass String full1 and String money from Menu to Account and set Text have error
Menu Controller class
public class MenuController implements Initializable {
@FXML
private Text nameuser;
String account;
void setData(String fullname, String username) {
nameuser.setText(fullname);
account = username;
}
@FXML
private void btnsp(ActionEvent event) throws Exception {
try {
Connection con;
con = Connect.Connect();
PreparedStatement pstm = con.prepareStatement("select fullname, money from account where username = ?");
pstm.setString(1, account);
ResultSet result = pstm.executeQuery();
if(result.next()) {
System.out.println(result.getString(1));
System.out.println(result.getString(2));
} else {
System.out.println("Fail!");
}
String fullname1 = result.getString(1);
String money = result.getString(2);
FXMLLoader loader = new FXMLLoader(getClass().getResource("Account.fxml"));
Parent root = loader.load();
Scene scene = new Scene(root);
Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
AccountController MenuController = loader.<AccountController>getController();
AccountController.setData(fullname1, money);
app_stage.hide();
app_stage.setScene(scene);
app_stage.show();
} catch (SQLException ex) {
System.out.println("SQLException");
System.out.println("Error message: " + ex);
}
}
}
Account Controller class
public class AccountController implements Initializable {
@FXML
private Text fullname;
@FXML
private Text money;
static void setData(String fullname1, String money) {
fullname.setText(fullname1);
fullname.setText(money);
}
}