Dimas Ari
Dimas Ari

Reputation: 156

OOP inheritence, parents variable value not updated on child

this is simple login handler, i never have problem like this when put it on same class. then i try to put it on child class and i don't know what happening. this is the GUI class

        final static Functions.F_Koneksi F_K = new Functions.F_Koneksi();
        final static Functions.F_Process F_P = new Functions.F_Process();
        final static GUIController F_GUI = new GUIController();
        protected javax.swing.JPasswordField jPasswordFieldPasswordLoginPane;
        protected javax.swing.JTextField jTextFieldUsernameLoginPane;

        ...

        private void jButtonLoginLoginPaneActionPerformed(java.awt.event.ActionEvent evt) {                                                      
            switch (F_GUI.DoLogin()) {
                case 1:
                    cl.show(MainPane, "BuyMovie");   
                    break;
                ...
                default:
                    LoginLabel.setText("username or password ... ");
            }
        } 

and this is the GUIController class

 int DoLogin(){
        try {
            System.err.println(jTextFieldUsernameLoginPane.getText());
            char[] PassChars = jPasswordFieldPasswordLoginPane.getPassword();
            String Pass = new String(PassChars);
            return F_P.F_Login(jTextFieldUsernameLoginPane.getText(), Pass);
        } catch (SQLException ex) {
            LoginLabel.setText("connection error");
        }
        return 3;
    }       

and this is the F_Login method on F_Process

public int F_Login(String User, String Pass) throws SQLException {
    ResultSet RS = Select("select * from blablabla"); //this query work already
    int level = 8;
    if (RS.next()) {
        level = RS.getInt("Level");
    }

    return level;
} 

the problem is when i set user and password textfield with right user pass its work but when user put it its not. i know something wrong with my OOP logic but i don't understand where. thank you

this is picture to make you understand what i mean

https://i.sstatic.net/1DsrF.png https://i.sstatic.net/uXmGZ.png

Upvotes: 0

Views: 77

Answers (1)

Kennedy Oliveira
Kennedy Oliveira

Reputation: 2281

Maybe its because the GUIController doesn't access the same jPasswordFieldPasswordLoginPane that the other gui access, to do it, you must pass the object to the GUIController class, like pass the reference in the constructor or setter method, and in the GUIController you access the correct jPasswordFieldPasswordLoginPane.

Upvotes: 1

Related Questions