java - How to set the Text in TextFields to the numbers of an Array -
i need set each textfield in jframe corresponding number in pre-generated array of numbers not know how.
this need like:
here actionlistener class working with:
public class randlistener implements actionlistener { private final jtextfield[] tf; public randlistener(jtextfield[] tf) { this.tf = tf; } @override public void actionperformed(actionevent e) { int [] rarray = new int[10]; random rnum = new random(); for(int k = 0; k < rarray.length; k++) { rarray[k] = rnum.nextint(100); } if(e.getactioncommand().equals("brand")) { for(int k = 0; k < tf.length; k++) { tf[k].settext(/*i need set text of textfields numbers in array*/); } } if(e.getactioncommand().equals("bmaxmin")) { //i need find maximum , minimum of array here } } }
read on how strings in java work. basically, if want turn number string:
tf[k].settext(/*i need set text of textfields numbers in array*/);
turns into:
tf[k].settext("" + rarray[k]);
i believe done automatically java; number boxing turns primitive type respective wrapper (int -> integer) , then tostring() called on integer object represents primitive type.
now, find minimum , maximum, you're going have think little bit. elementary problem companies give weed out bad candidates. figure out once on own , you'll never forget it. think of how human; take current biggest/smallest , compare whatever you're looking @ currently.
Comments
Post a Comment