public class Paint extends jframe{
Public Paint () {
setlocation (0, 0);
SetSize (400, 400);
Setdefaultcloseoperation (Exit_on_close);
Container Con=getcontentpane ();
Con.setlayout (New BorderLayout ());
Draw Dra=new Draw ();
Con.add (DRA);
Con.add (New button (), Borderlayout.south);
}
public static void Main (String args[]) {
Paint pai=new paint ();
Container Con=pai.getcontentpane ();
Con.setlayout (New BorderLayout ());
Draw Dra=new Draw ();
Con.add (DRA);
Pai.setvisible (TRUE);
Thread th=new thread (DRA);
Th.start ();
}
}
Class Draw extends JPanel implements runnable{
Color color;
@Override
public void Paint (Graphics g) {
TODO auto-generated method stubs
Graphics2D g2= (graphics2d) G;
int x=100;
int y=100;
String Str=new string ("Mafeng");
Font font =new font ("XXFarEastFont-Xingkai", font.bold,72);
G2.setfont (font);
G2.setcolor (color);
G2.drawstring (str, x, y);
System.out.println ("456");
}
public void Run () {
Random ran=new random ();
while (true) {
int R=ran.nextint (256);
int G=ran.nextint (256);
int B=ran.nextint (256);
Color=new Color (R, G, b);
Repaint ();
System.out.println ("123");
try{
Thread.Sleep (1000);
}catch (Interruptedexception e) {
E.printstacktrace ();
}
}
}
}
Text that will change color