swing - Java - Iterate through an array everytime a button is pressed -
i iterate through list every time button pressed, using jbutton, jtextfield , event's actionlistener. every time "next" button pressed next item in array should displayed in jtextfield. have created getters, setters , constructor, it's literally following piece i'm having trouble with.
@override public void actionperformed(actionevent evt){ object source = evt.getsource(); string[] item = getthing(); for(int = 0; < 3; ++){ string currenti = item[i]; } if(source.equals(btnnxt)){ txtdisplayfield.settext(currenti); } }
in if statement receive error "cannot find symbol", referring currenti.
you're initializing currenti
string
within for
loop's scope.
the variable therefore inaccessible outside for
loop.
move equality check , assignment inside loop.
for(int = 0; < 3; ++){ string currenti = item[i]; if(source.equals(btnnxt)){ txtdisplayfield.settext(currenti); // stop iteration found match break; } }
Comments
Post a Comment