Alternate Display Font Colour
I have this short code
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JTextArea;
publicclass Mainextends JFrame
{
public Main()
{
super("Colour Alternator");
alternate();
}
/**
* Creates the JTextArea with alternating colours
*/
publicvoid alternate()
{
setDefaultCloseOperation(EXIT_ON_CLOSE);
final JTextArea alternator =new JTextArea("This is where the text is displayed\n");
alternator.append("Hello World\n");
alternator.setForeground(Color.RED);
alternator.append("Hello World\n");
alternator.setForeground(Color.GREEN);
alternator.append("Hello World\n");
alternator.setForeground(Color.YELLOW);
alternator.append("Hello World\n");
alternator.setForeground(Color.BLACK);
alternator.append("Hello World\n");
alternator.setForeground(Color.BLUE);
alternator.append("Hello World\n");
setLayout(new BorderLayout());
getContentPane().add(alternator, BorderLayout.CENTER);
setBounds(100, 100, 500, 500);
setVisible(true);
}
publicstaticvoid main(String[] args)
{
new Main();
}
}
which the JtextArea displays with the last colour I have specified. I however, would like it to alternate the colour. Anyone?

