您的位置:首页 > 其它

动画,一个方框会慢慢变小变白

2015-08-10 09:51 239 查看
import javax.swing.*;
import java.awt.*;

public class Animate
{
int x=1;
int y=1;
public static void main(String [] args)
{
Animate gui=new Animate();
gui.go();
}
public void go()
{
JFrame frame=new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyDrawP drawP=new MyDrawP();
frame.getContentPane().add(drawP);
frame.setSize(500,270);
frame.setVisible(true);
for(int i=0;i<124;i++,y++,x++)
{
x++;
drawP.repaint();
try{
Thread.sleep(50);
}catch(Exception ex){}
}
}
class MyDrawP extends JPanel
{
public void paintComponent(Graphics g)
{
g.setColor(Color.white);
g.fillRect(0,0,500,250);
g.setColor(Color.blue);
g.fillRect(x,y,500-x*2,250-y*2);
}
}
}


注意:

fillRect(x,y,w,h)函数的作用是:填充一个矩形区域,x、y为起始坐标(即左上角坐标),后面两个参数分别为:w、h,是矩形区域的宽和高,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: