I’m trying to show all data that I got in the textarea
public static void randNumQueue(){
Queue<String> myQueue = new LinkedList<>();
if(average12==30){
long range = (long)randNum2 - (long)randNum1 + 1;
long fraction = (long)(range * random.nextDouble());
number = (int)(fraction + randNum1);
System.out.println(number);
Set mySet = new HashSet();
for (int j = 0; j<number; j++)
{
int pick;
do{
pick = random.nextInt(number)+1;
}while(!mySet.add(pick));
myQueue.add(Integer.toString(pick));
}
System.out.println("the queue size: "+myQueue.size());
sizeQ = myQueue.size();
Iterator it = myQueue.iterator();
while(it.hasNext()){
String iteratorValue = (String)it.next();
Qnum = Integer.parseInt(iteratorValue);
System.out.println("queue next value: "+Qnum);
}
}
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(b1)){
randomAverage();
testAmount = testAmount + 1;
label5.setText(""+testAmount);
area3.setText(""+sizeQ);
area1.setText(""+Qnum);
}
}
area1 is area text which I’m trying to show all data which I got from IteratorValue
from the above function area1 just showed the last value which I got from iteratorValue
anyone know how to show all the value in area1(textarea)?
Use
setTextwhen you want to replace the contents of the text area, useJTextArea#appendwhen you want to add text to the end of the text areaUpdated
It’s a “little” difficult to assess what it is you are trying to do, but something like…
In your action performed method, remove
area1.setText(""+Qnum);. This will append each result to the text area. If you want to clear the text, use something likearea1.setText(null)