First of all, this is a classic homework task. So I would like to leave the coding to you.
I would define the colors, maybe selectable via a JcolorChooser Dialog.
These colors need to be applied to the text. To make that simpler, I would Not think of a JTextArea but of a Scrollpane, that I add Labels to.
These Labels should be custom. They would hold the colors and apply one or the other to the Label:
public class CustomLabel extend JLabel{
private final Color oColor1, oColor2;
public CustomLabel(){
super(strText);
this.ignition();
}
private void ignition(){
this.setForeground(oColor1);
}
}
http://www.leepoint.net/notes-java/GUI/components/10labels/12labelfontcolor.html[
^]
How to use Scrollpane[
^]