可惜不是你,陪我到最后
一个不断更新渐变的彩色画板,
一个不断更新渐变的彩色画板,
多谢多谢
/*
* TestApplet.java
*
* Created on 2006年11月24日, 下午8:29
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author lbf
*/
import java.awt.*;
import javax.swing.*;
public class TestApplet extends JApplet implements Runnable{
private Color c1,c2;
/** Creates a new instance of TestApplet */
public TestApplet() {
}
public void init(){
c1=Color.RED;
c2=Color.BLUE;
new Thread(this).start();
}
public void paint(Graphics g){
GradientPaint gp=new GradientPaint(0,0,c1,0,300,c2);
Graphics2D g2d=(Graphics2D)g;
g2d.setPaint(gp);
g2d.fillRect(0,0,300,300);
this.setSize(300,300);
}
public void run(){
while(true){
try{
Thread.sleep(200);
c1=new Color((int)(Math.random()*0xFFFFFF));
c2=new Color((int)(Math.random()*0xFFFFFF));
repaint();
} catch(Exception exe){
exe.printStackTrace();
}
}
}
public static void main(String[] args) {
TestApplet ta=new TestApplet();
JFrame jf=new JFrame("application");
jf.getContentPane().add(ta,BorderLayout.CENTER);
jf.setSize(300,300);
jf.setLocationRelativeTo(null);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ta.init();
ta.start();
}
}
你运行看看吧,,
可以做为applet运行,也可以做为application运行,因为它有main方法
不愧是老大
辛苦了
偶考回去研究研究
用的不是自己的机子,要走了,明天在来讨教哈~