ActionListener works perfectly after second time it's pressed -


entercommand.addactionlistener(new actionlistener() {

        public void actionperformed(actionevent event) {             string userinput = enterword.gettext();             string userinput2 = entersecondword.gettext();             if (" ".equals(userinput) || " ".equalsignorecase(userinput2)) {                  joptionpane.showmessagedialog(null, "the space empty please try again");              } else {                 enterword.settext(" ");                 entersecondword.settext(" ");                 system.out.println("test");                 japanesestudiesexcel je = new japanesestudiesexcel();                 je.japanesestudiesexcel(userinput, userinput2);              }             ;         }     }); 

it checks input in fieldbox second time listener fired, first time not work. better explain this, when user enters nothing doesn't check empty string writes empty box excel. second time actionlistener fired checks , reports message user. why occur?

you're testing space, not empty string:

(" ".equals(userinput) || " ".equalsignorecase(userinput2)) 

remove space:

("".equals(userinput) || "".equalsignorecase(userinput2)) 

also, why works second time click it:

enterword.settext(" "); entersecondword.settext(" ");  

you're setting field space, true next time around.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -