码迷,mamicode.com
首页 > 其他好文 > 详细

会变色的文字

时间:2015-04-27 23:09:08      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:

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 自动生成的方法存根
Graphics2D g2=(Graphics2D)g;

int x=100;
int y=100;
String str=new String("mafeng");

Font font =new Font("华文行楷",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();
}
}


}
}

会变色的文字

标签:

原文地址:http://www.cnblogs.com/mafeng/p/4461442.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!