0
People who work with Javafx, I need a lot of help, I’m trying to pass data from one screen to another but I can’t.
In my project I log in with a user searching in the database. Each user has one id
. I need, by the time he logs in, I can send this id
to the main screen to be able to touch the other things with this id
.
I have Login.Controller, login.fxml. login.tela, and the main screen the same thing, following the MVC standard.
In the code below I log in, at that time I wanted to send the id
user to my main screen.
public void logar() {
DAO<Usuarios> dao = new DAO<Usuarios>(Usuarios.class);
List<Usuarios> users = dao.obterTodos();
for (int i = 0; i < users.size(); i++) {
if (txEmail.getText().equals(users.get(i).getEmail()) && txSenha.getText().equals(users.get(i).getSenha())) {
idUsu = users.get(i).getId();//consigo guardar o id nessa varivel que criei
Principal p = new Principal();
i = users.size();
fechar();
try {
p.start(new Stage());
Alert alert = new Alert(AlertType.CONFIRMATION);alert.setTitle(idUsu.toString());
alert.show();//fiz um teste de alerte pra ver se realmente pegava o id na variavel que criei
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}