user interface - java- why is my "deposit" method not working for my ATM with gui? -


i'm making atm in user must first enter pin (1234), , once pin entered correctly, user can either withdraw 50, 100, or 200 dollars or make deposit under $1000. withdraw methods working, when run program , try make deposit, nothing happens after enter amount , try hit "enter" button. seems if enter button not working. here code used deposit method:

 if (event.getsource() == deposit) {     instructionscreen.settext("enter amount deposit, click enter.");      if (event.getsource() == enter) {        savescreen = displayinput.gettext();        double add = double.parsedouble(savescreen);        if (add <= 1000) {           balance += add;           instructionscreen.settext("your new balance $" + balance + ".");        }        else {           instructionscreen.settext("the maximum amount can deposit $1000. please enter new amount.");           displayinput.settext("");           if (event.getsource() == enter) {              savescreen = displayinput.gettext();              add = double.parsedouble(savescreen);           }        }         displayinput.settext("");        system.out.println("a deposit of $" + add + "was made. new balance $" + balance);     }  } 

what wrong code causing deposit not when hit enter after entering amount deposit?

your program work great if linear console program, not how event-driven programming works. instead of expecting source change , magically deposit enter, need change state of object if deposit selected, perhaps changing boolean field, , testing field in enter's action listener.

e.g.,

if (event.getsource() == deposit) {     instructionscreen.settext("enter amount deposit, click enter.");     depositstate = true;  // boolean field } else if (event.getsource() == enter) {     if (depositstate) {         depositstate = false; // reset          savescreen = displayinput.gettext();         double add = double.parsedouble(savescreen);         // .... etc 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -