我在这里有一个登录表单,包括用户名和密码 我有另一个表格可以记录客户数据,填写的文本框很少。 喜欢客户名称; 客户电子邮件和客户联系。 基本上当用户接到客户的电话时会发生这种情况。 用户输入他或她的用户名和密码,登录系统。 和用户必须填写文本框,提交后,数据保存在mysql数据库中。 所以mysql有一个名为customer的数据库。 it有五个cloumns cus id,cusName,cusAdress,cusContact,contactUser 所以我创建了一个名为MysqlConnect的类,它拥有所有的setter和getter。 所以我创建了一个名为setName和getName的getter和setter
Here i have a login form includes username and password and i have another form which can records customer data and there are few text boxes to fill. like customer name; customer email and customer contact. the basically what happens is when user get a call from a customer. user put his or her user name and password, login to the system. and user has to fill textboxes and after submit it, data saves in a mysql database. so mysql has a database called customer. it has five cloumns cus id,cusName,cusAdress,cusContact,contactUser So i have created a class called MysqlConnect which holds all setters and getters. so i have created a getter and setter called setName and getName
public class MysqlConnect { String Name; public void setName(String newName){ Name = newName; } public String getName(){ return Name; } }然后我在登录表单中设置一个值
then i set a value in the login form
nameSet = uName.getText();//gets the username from a textbox MysqlConnect cont = new MysqlConnect(); cont.setName(nameSet);之后,我已经在其他表格中实施了一个getter来调用客户数据。
after that i have implement a getter in the other form call customer data.
MysqlConnect cont = new MysqlConnect(); String namet = cont.getName(); JOptionPane.showMessageDialog(null, "Data Saved Successfully."+nameUser+"");但它显示为空值。 我尝试过: 我描述的getter和setter?
But it shows a null value. What I have tried: Getters and Setters as i Described?
推荐答案是的,因为你创建了一个新的 MysqlConnect 实例时间,所以它不会包含任何数据。您应该在应用程序的开头创建一个类的实例。这样它将始终包含最新的值。 Yes, because you create a new instance of MysqlConnect each time, so it will not contain any data. You should have one instance of the class created at the start of your application. That way it will always contain the most up to date values.
更多推荐
如何将值从一个帧传递到另一个帧
发布评论