so in process of making atm system have ask user if wish create new account. meant title of atm (located @ top) have change "login" "account creation" or somesuch. on button press text of jlabel title needs change. problem when press button new account, happens terminal window pops indicating nullpointerexception @ following line:
title.settext("create new account");
from remember, means object "title" null. problem shouldn't null, absolutely sure established , can't think of reason why returning error me.
here related code:
public class accountsystem extends jframe implements actionlistener { public static account currentuser = new account(); //this methods know account logged in can perform operations on it. public static int count=0; public static account acc[] = new account[1000]; public static string parts[] = new string[3]; private jbutton login, logout, createacc, deposit1, deposit2, withdraw1, withdraw2, transfer1, transfer2, nevermind; private jpanel optionson, optionsoff, loginarea, mainarea, titlecard, depositscreen, withdrawscreen, transferscreen, newaccountscreen; private jtextfield username, password, transfer, depositarea, withdrawarea, retypearea; private jlabel userprompt, depositprompt, withdrawpromt, balancedisp, passwordprompt, mainmessage, title; private string newuser, newpass, newpassconfirm; borderlayout borderlayout; gridlayout gridlayout; public accountsystem() { borderlayout = new borderlayout(); borderlayout.sethgap(5); borderlayout.setvgap(5); //establishing our buttons here. jbutton login = new jbutton("login"); login.addactionlistener(this); jbutton createacc = new jbutton("new account"); createacc.addactionlistener(this); jbutton withdraw2 = new jbutton("withdraw"); jbutton transfer2 = new jbutton("transfer"); //establishing our panels here. jpanel optionson = new jpanel(); jpanel optionsoff = new jpanel(); jpanel loginarea = new jpanel(); jpanel titlecard = new jpanel(); //establishing our jlabel here. jlabel userprompt = new jlabel("username: "); jlabel passwordprompt = new jlabel("password: "); jlabel title = new jlabel("login"); //establishing our textfields here. jtextfield username = new jtextfield(20); jtextfield password = new jtextfield(20); jtextfield transfer = new jtextfield(20); jtextfield withdrawarea = new jtextfield(20); mainscreen(getcontentpane()); //building gui here. titlecard.setsize(500,50); titlecard.setlocation (0,0); loginarea.setsize(300,450); loginarea.setlocation(0,50); optionsoff.setsize(150,450); optionsoff.setlocation(300,50); titlecard.add(title); loginarea.add(userprompt); loginarea.add(username); loginarea.add(passwordprompt); loginarea.add(password); loginarea.add(login); loginarea.add(createacc); getcontentpane().setlayout(null); getcontentpane().add(titlecard); getcontentpane().add(loginarea); getcontentpane().add(optionsoff); } public void actionperformed (actionevent e) { if ((e.getactioncommand()).equals("login")) { login(); } else if ((e.getactioncommand()).equals("new account")) { title.settext("create new account"); } }
you define title variable class variable:
private jlabel userprompt, ...., title;
and local variable:
jlabel title = new jlabel("login");
the title.settext() method access class variable null. change:
//jlabel title = new jlabel("login"); title = new jlabel("login");
you need variable want treat class variable.
Comments
Post a Comment