如何在同一个GUI中的不同jframe中使textfield值可用? [英] how to make a textfield value available across different jframes in the same gui?

查看:155
本文介绍了如何在同一个GUI中的不同jframe中使textfield值可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个程序,该程序使用几个不同的交互菜单来允许用户访问系统的不同部分.我正在使用Netbeans来帮助编码.

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.

此刻我被困在任务上.

当用户通过登录"表单登录系统时,系统将验证详细信息,并根据凭据将用户重定向到user_detailsadmin_menu.这样很好.从那里,用户可以访问一个表单,该表单使他们可以更新其已保存在数据库中的详细信息.

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.

考虑到这一点,我如何从另一个jform(User_details)中检索位于jform登录名中的文本字段Username中的估算值,所以User_details jform仅在登录成功后才打开(一旦发生登录将被丢弃,并打开user_details.

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).

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) {
            }
        }


我怎样才能使User_details Jform获得在文本字段用户名中插入的内容?


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

推荐答案

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

If your program doesn't end(after the user has logged in once) u can save the entire information in a String array and just validate the array and redirect the user to the given form. eg.

//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);
}

这篇关于如何在同一个GUI中的不同jframe中使textfield值可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆