java - looping jtextfields so it clears if anything but an integer is entered -


i know need code looped i'm not sure how it, don't know have loop? clears textfields @ minute, want textfield has integer cleared. appreciated.

try {     int = integer.parseint(theapp.tred.gettext());     int b = integer.parseint(theapp.tgreen.gettext()); // uses                                                         // information                                                         // entered     int c = integer.parseint(theapp.tblue.gettext());      if (a < 0) {         = 200; // if statements values above , below targets                             // set         tred.settext("200");     }      if (a > 255) {         = 255;         tred.settext("255");     }     if (b < 0) {         b = 200;         tgreen.settext("200");     }      if (b > 255) {         b = 255;         tgreen.settext("255");     }      if (c < 0) {         c = 200;         tblue.settext("200");     }     if (c > 255) {         c = 255;         tblue.settext("255");     }     message.settext(" work submitted by:"); // text     message.setforeground(new color(a, b, c)); // changes colour                                                         // desired input  } catch (numberformatexception ex) {      message.settext("invalid input! please enter numbers only"); // text     message.setforeground(new color(0, 0, 0)); // original text set                                                 // red     tred.settext("");     tgreen.settext("");     tblue.settext(""); // clears box if not integer } 

you can separate try-catch block 3 parts:

int = -1; try {     = integer.parseint(theapp.tred.gettext());     if (a < 0) {         = 200;          tred.settext("200");     }     if (a > 255) {         = 255;         tred.settext("255");     }     //do needed things here } catch (exception e) {     message.settext("invalid input! please enter numbers only"); // text     message.setforeground(new color(0, 0, 0));      tred.settext(""); } 

(this tred, others pretty same).


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -