How to close the current screen after opening a new javafx

Asked

Viewed 234 times

1

well I have this code that will open a new screen but the old screen is still open:

 if (conn.resultset.next()) {
            MenuPrincipal p = new MenuPrincipal ();

code:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package semeqapp;

import Conexao.ConnectionFactory;
import MenuPrincipal.MenuPrincipal;
import java.io.IOException;
import java.net.URL;
import java.sql.SQLException;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import javax.swing.JOptionPane;

/**
 *
 * @author SpiriT
 */
public class LoginFXController implements Initializable {

    @FXML
    private TextField jLogin;
    @FXML
    private PasswordField jSenha;

    @FXML
    private void handleButtonAction(ActionEvent event) {

    }
    @FXML
    private void validar(ActionEvent event) {
        validaLogin();
    }
    public void validaLogin(){
        try {
            ConnectionFactory conn = new ConnectionFactory();
            conn.getConnection();

            String sql = "SELECT login,senha FROM usuario where login = '" + jLogin.getText() + "' and  senha = '" + jSenha.getText() + "'";
            conn.executeSQL(sql);

            //Se houver resultado, ou seja, se validar o usuario e senha, faça algo.
            if (conn.resultset.next()) {
            MenuPrincipal p = new MenuPrincipal ();

                try {
                    p.start(new Stage());
                } catch (IOException ex) {
                    Logger.getLogger(LoginFXController.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else {
            JOptionPane.showMessageDialog(null, "Senha Invalida");
            }
        }catch(SQLException e){
            System.out.println("Erro: "+e);
        }
    }
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
    }    

}
  • And where do you close the old window? In fact, just with this code, it is difficult to point out to you where the problem is because it is probably not there, so it would be pertinent for you to edit your question to put it.

  • @Victorstafusa he still does not close the old window that is a method I call on a button that will open the Menuprincipal window, but the LOGIN screen is still open I wanted to close it there.

  • but I edited, in case I have a class in the controller, to validate data and if validate will open another screen that is the Menuprincipal screen, but the old screen is still open, I wanted to create a method to close the screen or even something to put in if.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.