java - Can't Get ActionListener to work -


here code, account basic class doesn't special. have tried action listener work , know missing silly. made gui in jigloo , think problem in actual main? need add something? or going wrong. never done gui stuff before. first programming class have taken , professor seems think should able without issue. ideas?

import java.awt.event.actionevent; import javax.swing.jbutton; import javax.swing.jeditorpane; import javax.swing.jtextfield; import javax.swing.windowconstants; import javax.swing.swingutilities;   import java.awt.event.actionlistener;     @suppresswarnings("serial") public class button extends javax.swing.jframe implements actionlistener {     public jbutton loginbutton;     public jtextfield bankinfobutton;     public jbutton transgerbutton;     public jbutton jbutton1;     public jtextfield moneytextfield;     public jtextfield sendto;     public jeditorpane account1;     public jtextfield accountpw;     public jtextfield accountname;     public jbutton balancebutton;     public jbutton withdrawbutton;     public jbutton depositbutton;     public jbutton logoutbutton;     /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/       public account theac = new account();     public account[] accountlist = new account[10];      public string tempaccountname;     public string tempaccountpw;     public int tempindex;     public double tempbalance;     public transfer thet = new transfer();     public transfer[] transferlist = new transfer[10];        public static void main(string[] args) {         swingutilities.invokelater(new runnable() {             public void run() {                 button inst = new button();                 inst.setlocationrelativeto(null);                 inst.setvisible(true);             }         });     }      public button() {         super();         initgui();     }      private void initgui() {         try {             setdefaultcloseoperation(windowconstants.dispose_on_close);             getcontentpane().setlayout(null);             {                 loginbutton = new jbutton();                 getcontentpane().add(loginbutton);                 loginbutton.settext("login");                 loginbutton.setbounds(12, 12, 120, 44);             }             {                 logoutbutton = new jbutton();                 getcontentpane().add(logoutbutton);                 logoutbutton.settext("log out");                 logoutbutton.setbounds(137, 12, 120, 44);             }             {                 bankinfobutton = new jtextfield();                 getcontentpane().add(bankinfobutton);                 bankinfobutton.settext("displays bank account information");                 bankinfobutton.setbounds(336, 215, 277, 189);             }             {                 depositbutton = new jbutton();                 getcontentpane().add(depositbutton);                 depositbutton.settext("deposit");                 depositbutton.setbounds(12, 150, 120, 50);             }             {                 withdrawbutton = new jbutton();                 getcontentpane().add(withdrawbutton);                 withdrawbutton.settext("withdraw");                 withdrawbutton.setbounds(151, 150, 120, 50);             }             {                 balancebutton = new jbutton();                 getcontentpane().add(balancebutton);                 balancebutton.settext("balance");                 balancebutton.setbounds(12, 223, 120, 52);             }             {                 transgerbutton = new jbutton();                 getcontentpane().add(transgerbutton);                 transgerbutton.settext("transfer");                 transgerbutton.setbounds(12, 298, 120, 52);             }             {                 accountname = new jtextfield();                 getcontentpane().add(accountname);                 accountname.settext("please enter account name");                 accountname.setbounds(12, 76, 193, 23);             }             {                 accountpw = new jtextfield();                 getcontentpane().add(accountpw);                 accountpw.settext("please enter account password");                 accountpw.setbounds(12, 115, 193, 23);             }             {                 account1 = new jeditorpane();                 getcontentpane().add(account1);                 account1.settext("please enter account transfer funds to");                 account1.setbounds(0, 370, 313, 34);             }             {                 moneytextfield = new jtextfield();                 getcontentpane().add(moneytextfield);                 moneytextfield.settext("enter cash here");                 moneytextfield.setbounds(163, 258, 99, 23);             }             {                 jbutton1 = new jbutton();                 getcontentpane().add(jbutton1);                 jbutton1.settext("create account");                 jbutton1.setbounds(268, 12, 130, 44);             }             pack();             this.setsize(651, 460);         } catch (exception e) {             //add error handling code here             e.printstacktrace();         }        }       public void actionperformed(actionevent e) {         if(e.getsource() == jbutton1)          {              bankinfobutton.settext("hello");          }         if(e.getactioncommand().equals("create account"))          {             if(theac==null)             {                 bankinfobutton.settext("you must first log in");             }               if(accountpw.gettext() != null)             {             theac.setpassword(accountpw.gettext());             bankinfobutton.settext("new account created!");             accountlist[account.getnumaccount()-1] = theac;              bankinfobutton.settext("account created!");             bankinfobutton.settext(theac.tostring());             }             else             {             bankinfobutton.settext("you must enter password create account.");             }       }          if(e.getactioncommand().equals("print account list")){             for(int = 0; <accountlist.length;i++)             {                  bankinfobutton.settext(accountlist[i].tostring());             }         }         if(e.getactioncommand().equals("deposit"))          {             if(theac==null)             {                 bankinfobutton.settext("you must first log in");             }             theac.deposit(double.parsedouble(moneytextfield.gettext()));             bankinfobutton.settext("your new balance is: " + string.valueof(theac.getbalance()));         }         if(e.getactioncommand().equals("withdrawl"))          {             if(theac==null)             {                 bankinfobutton.settext("you must first log in");             }              //theac.withdraw(double.parsedouble(moneytextfield.gettext()));             bankinfobutton.settext("your new balance is: " + string.valueof(theac.getbalance()));       }         if(e.getactioncommand().equals("balance"))          {             if(theac==null)             {                 bankinfobutton.settext("you must first log in");             }              bankinfobutton.settext("your balance is: " + string.valueof(theac.getbalance()));      }         if(e.getactioncommand().equals("login"))          {             if(theac==null)             {                 bankinfobutton.settext("you must first log in");             }             for(int = 0;i<10;i++)             {                 if(accountname.gettext().equals(accountlist[i].getname()))                         {                             tempaccountname = accountlist[i].getname();                          }             for(int n = 0;i<10;i++)             {                  if(accountpw.gettext().equals(accountlist[i].getpassword()))                 {                     tempaccountpw = accountlist[i].getpassword();                     if(i==n)                      n= tempindex;                     else                     {                         bankinfobutton.settext("invalide username or password");                     }                 }              }             theac = accountlist[tempindex];             }         if(e.getactioncommand().equals("log out"))         {             if(theac==null)             {                 bankinfobutton.settext("you must first log in");             }             theac = null;             bankinfobutton.settext("you have logged off");          }         if(e.getactioncommand().equals("transfer"))         {             thet = transferlist[tempindex];             thet.sethistory(accountname.gettext(), sendto.gettext(), double.parsedouble(moneytextfield.gettext()));         }      } }  } 

you never register actionlistener of components:

jbutton1.addactionlistener(this); 

on different note consider using layout manager manage positioning & sizing of components.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -