Hello! This is my first post, so be gentle. :-)
I am just getting started in Java and am writing a gui app to take a list of PC's from a JTextArea on the left, and reboot them one at a time. Then on the right, in another JTextArea, output whether the reboot was successful, or couldn't ping it, etc. The trouble is, when I run the program, it steps through each PC in the list just like I want it to. Reboots them just as designed. Appends to the JTextArea just as designed. But it does not update the text area until it makes it through the entire list. If I have 100 PCs in the list, it attempts to reboot them all, then BOOM all the appends to the log text area are applied at once. Is there any way to update the text area as an attempt is made on each PC in the list?
Here's the reboot code.
try
{
Runtime runtime = Runtime.getRuntime();
// TODO Auto-generated method stub
if (e.getSource() == leave)
{
System.exit(0);
}
else if (e.getSource() == reboot)
{
StringTokenizer tokenizer = new StringTokenizer(pclist.getText() + String.valueOf(CRLF));
//StringTokenizer tokenizer = new StringTokenizer(pclist.getText());
//System.out.println(String.valueOf(CRLF)+ "this");
while(tokenizer.hasMoreTokens())
{
computers.add(tokenizer.nextToken());
}
log.setText("");
//System.out.println(computers.size());
for(int i = 0; i < computers.size(); i++)
{
try
{
Process checkpulse = runtime.exec("ping " + computers.get(i) + " -n 1");// | find '"Reply"'");
int checkPulseExitVal = checkpulse.waitFor();
//System.out.println(checkPulseExitVal);
if (checkPulseExitVal != 0)
{
log.append("Unable to Ping " + computers.get(i) + "\r\n");
log.revalidate();
//log.setCaretPosition(i);
}
else if(checkPulseExitVal == 0)
{
//System.out.println(computers.size());
Process restart = runtime.exec("shutdown -r -t 0 -m \\\\" + computers.get(i));
int restartExitVal = restart.waitFor();
if (restartExitVal == 0)
{
log.append(computers.get(i) + " Rebooted\r\n");
log.revalidate();
//log.validate();
//log.setCaretPosition(i);
}
else
{
log.append("Sumpin happened and I'm not sure what.\r\n");
log.revalidate();
}
}
}
catch (InterruptedException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
catch (IOException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
{code}