java - Converting User Input to Integer with Custom Error Message -
i working on program accepts user input through joptionpane window. goal create if statement validates user input integer. i've tried integer.parseint method throws exception, cannot display own joptionpane window informing user of mistake. i'm new programming , cannot think of way convert string integer (or @ least way works) use in if statement. ideas?
thanks!
if integer somehow after joptionpane
message displayed, may want take @ code continuously prompts user enter valid integer:
int number = 0; boolean ok = false; string input = ""; while(!ok) { try { number = integer.parseint( input ); ok = true; } catch(exception e) { // change joptionpane message here warn user. } }
Comments
Post a Comment