所有JFrames对于我的PAT上学方法编辑它,我做我的默认构造函数和这里看到参数化的构造函数:默认/参数化的构造函数=如何在包装
public class Client
{
//attributes
private String clientName;
private String clientPass;
private double currentBal;
private double savingsBal;
private boolean verify;
//default constructor
public Client()
{
clientName = "";
clientPass = "";
currentBal = 0.0;
savingsBal = 0.0;
verify = false;
}
//parameterised constructor
private Client(String username,String password,int accNum,
double curBal,double savBal, boolean ver)
{
clientName = username;
clientPass = password;
currentBal = curBal;
savingsBal = savBal;
verify = ver;
}
的问题是,我有在此之后创建了几个方法,为了让它们正常工作,它们需要更改我的构造函数中为包中的所有不同表单分配的值。 不幸的是,这似乎并不奏效。无论我做什么,变量只是暂时改变。 我错过了什么吗?有什么我应该在我的构造函数中完成不同的工作,还是需要在我的方法中做一些额外的工作才能更改。
所有帮助非常感谢。 :)
编辑: 这里是我的方法之一:
public void newClient(String username,String password) throws IOException
{
//Sets username and password to user input and assigns the Client
account balances.
clientName = username;
clientPass = password;
savingsBal = (int)((Math.random()*100000000))/100.0;
currentBal = (int)((Math.random()*100000000))/100.0;
//Calls BufferedWriter to write a line to the text file with all
user information.
BufferedWriter bw = new BufferedWriter (new
FileWriter("ClientDatabase.txt",true));
bw.write(clientName+"_"+clientPass+"_"+currentBal+"_"+savingsBal);
bw.newLine();
//Closes BufferedWriter
bw.close();
}
//Verifies new Client via their username and password.
这工作正常,并且它是所有写入文本文件。但是,当我尝试在我的任何其他JFrames中使用这些值中的任何一个值时,似乎它们已被重置为0或空值...
你不在示例中引用'Client'类的实例。 'newClient'是什么类的方法的一员?可能不是“客户”。你只能在这个类中使用像这样的类变量。在你需要引用的地方(比如'Client c = new Client()'),然后你可以改变那些实例成员(比如'c.setName(aName)') – Fildor