0

I'm creating a program that uses several different interacting menus to allow the user to access different parts of the system. I'm using Netbeans to help with the coding.

At the moment I'm stuck on a task.

When a user logs into the system through a "login" form, the system validates the details, and that user is redirected to either a user_details or an admin_menu depending on the credentials. That much works fine. From there, the user is able to access a form that allows them to update their details which are already saved in the database.

The only way I've found to limit the simple user to update their details is to ask them to login again, and from there retrieve their details so that they can be updated. This process is messy, but it works.

With that in mind how do I retrieve whatever was imputed in the textfield Username that is located in the jform Login from another jform (User_details), the User_details jform only opens once the login is successful (once that occurs login is discarded and user_details is opened).

Here is part of my log in code :

String sql = "select * from user where Username =? and password=?";
        try {
            pst = con.prepareStatement(sql);
            pst.setString(1, username.getText());
            pst.setString(2, password.getText());
            rs = pst.executeQuery();

            int count = 0;
            while (rs.next()) {
                count = count + 1;
            }
            if (count == 1) {
                JOptionPane.showMessageDialog(null, "Access Granted");
                if ("manager@manage.com".equals(t.getText())) {
                    rs.close();
                    pst.close();
                    close();
                    Admin_menu am = new Admin_menu();
                    am.setVisible(true);
                } else {
                    rs.close();
                    pst.close();
                    close();
                    User_details M = new User_details();
                    M.setVisible(true);
                }
            } else {
                JOptionPane.showMessageDialog(null, "Incorrect Username or Password");
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex);

        } finally {
            try {
                rs.close();
                pst.close();
            } catch (Exception ex) {
            }
        }

how can i make the User_details Jform get what ever was imputed in the textfield username?

4

1 回答 1

-1

如果您的程序没有结束(在用户登录一次之后),您可以将整个信息保存在一个字符串数组中,然后验证该数组并将用户重定向到给定的表单。例如。

//At login
String a[]=new String[2];
a[0]=username.getText();
a[1]=new String(pass.getPassword());
if(validate(a)){
   homescreen.setVisible(true);
}

//when user wishes to go to his homescreen
if(validate(a)){
   homescreen.setVisible(true);
}
于 2012-08-12T03:40:30.627 回答