public int[] doInBackground()
{
int[] finalNumber = new int[2];
finalNumber[0] = 0;
finalNumber[1] = 0;
int count = 0;
int[] forDisplay = new int[2];
outerLoop:
for(int i = 1; i <= findUpTo; i++)
{
forDisplay[0] = i;
forDisplay[1] = 2;
publish(forDisplay);
for(int a = 1; a <= i; a++)
{
if(isCancelled())
break outerLoop;
else
{
try
{
Thread.sleep(numGen.nextInt(5));
}
catch(InterruptedException e)
{
e.printStackTrace();
}
forDisplay[0] = a;
if(i%a == 0)
{
forDisplay[1] = 1;
count++;
if(count > finalNumber[1])
{
finalNumber[0] = a;
finalNumber[1] = count;
}
}
else
{
forDisplay[1] = 0;
}
publish(forDisplay);
}
}
setProgress(100*(i+1)/findUpTo);
count = 0;
}
return finalNumber;
}
protected void process(List<int[]> publishedValues)
{
for(int i = 0; i < publishedValues.size(); i++)
{/*
if(publishedValues.get(i)[1] == 1)
{
numbers.setFont(new Font("Serif", Font.ITALIC, 16));
}
else if(publishedValues.get(i)[1] == 2)
{
numbers.setFont(new Font("Serif", Font.BOLD, 18));
numbers.append("\t");
}*/
numbers.append(publishedValues.get(i)[0] + "\n");
//numbers.setFont(new Font("Serif", Font.PLAIN, 16));
}
}
I'm not sure why this isn't working; if someone could help I'd appreciate it. I am trying to output forDisplay[0] in a JTextArea as it gets published, once. forDisplay[1] is used to determine the font in process (I commented the font changes out for now, they also were not working though it was going into the ifs in process [there was repeating text indentation])
The problem is that process seems to be appending the same number multiple times in a row and skipping others and I have no idea why.
The program itself is tasked with finding a number with the most divisors that produce no remainder from 1 to "findUpTo" (user input).
I'm rather new to SwingWorker so I'm having some difficulties understanding this issue.