Text that will change color

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.