Alright guys, I have been working a lot with SWING but recently started learning some FX. I have had good progress with it so far, I've been learning a lot. In Swing it was quite easy to declare a global variable and then use it across all your frames without any issues or whatsoever. However in JavaFX its quite a problem.
I have searched for this problem everywhere but I just cant seem to find the right answer.
So I got a few textfields that are taking input from the user, I'd like to save the input and display it on a new textfield in a new scence.
Here is the code
FirstController.java
private void reggy(ActionEvent event) {
try {
String username_text = username.getText().trim();
String password_text = password.getText().trim();
Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/store","root","password");
Statement st = (Statement) conn.createStatement();
String sql = "select username, password from users where username ='"+username_text+"' and password ='"+password_text+"'";
ResultSet rs;
rs = st.executeQuery(sql);
int count = 0;
while(rs.next()) {
count = count +1;
}
if(count == 1){
AnchorPane pane = FXMLLoader.load(getClass().getResource("second.fxml"));
rootpane.getChildren().setAll(pane);
System.out.println("User Found, Logged in");
}
Now the main question is how I can get the variable "String username_text" ready for use in a different FXML document (second.fxml)
Thanks a lot in advance. Really appreciate the help. A beginner here trying to work his way through FX.