10 Seconds Count Down

在这里插入图片描述

import javax.swing.*;

import java.awt.*;
import java.util.*;

class FireworkWindow extends JFrame{
	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		FireworkWindow  fw=new FireworkWindow();
	}
	public FireworkWindow()
	{
		FireworkPanel fp=new FireworkPanel();
		Thread t=new Thread(fp);
		t.start();
		this.add(fp);
		this.setLocation(100, 20);
		this.setSize(1000,700);
		this.setVisible(true);
	}
}
class FireworkPanel extends JPanel implements Runnable{
	int timesDown=10;
	int n=10;
	Vector<Ball> bs=new Vector<Ball>();
	public FireworkPanel()
	{
		for(int i=0;i<n;i++)
		{
			Ball b=new Ball();
			bs.add(b);
		}
	}
public void paint(Graphics g)
	{
		super.paint(g);
		g.fillRect(0, 0, 1000, 700);
		String t=String.valueOf(timesDown);
		g.setColor(Color.white);
		g.setFont(new Font("微软雅黑",Font.ITALIC,500));
		g.drawString(t, 300, 500);
		g.setColor(Color.orange);
		for(int i=0;i<bs.size();i++)
		{
			bs.get(i).setX((int)(Math.random()*900));
			bs.get(i).setY((int)(Math.random()*600));
			g.fillOval(bs.get(i).getX(), bs.get(i).getY(), 20, 20);
			System.out.println(Math.random()*600);
			System.out.println(bs.get(i).getX()+"   "+ bs.get(i).getY());
		}
g.setColor(Color.red);
		for(int i=0;i<bs.size();i++)
		{
			bs.get(i).setX((int)(Math.random()*900));
			bs.get(i).setY((int)(Math.random()*600));
			g.fillOval(bs.get(i).getX(), bs.get(i).getY(), 20, 20);
			System.out.println(Math.random()*600);
			System.out.println(bs.get(i).getX()+"   "+ bs.get(i).getY());
		}
g.setColor(Color.yellow);
		for(int i=0;i<bs.size();i++)
		{
			bs.get(i).setX((int)(Math.random()*900));
			bs.get(i).setY((int)(Math.random()*600));
			g.fillOval(bs.get(i).getX(), bs.get(i).getY(), 20, 20);
			System.out.println(Math.random()*600);
			System.out.println(bs.get(i).getX()+"   "+ bs.get(i).getY());
		}
g.setColor(Color.green);
		for(int i=0;i<bs.size();i++)
		{
			bs.get(i).setX((int)(Math.random()*900));
			bs.get(i).setY((int)(Math.random()*600));
			g.fillOval(bs.get(i).getX(), bs.get(i).getY(), 20, 20);
			System.out.println(Math.random()*600);
			System.out.println(bs.get(i).getX()+"   "+ bs.get(i).getY());
		}
g.setColor(Color.blue);
		for(int i=0;i<bs.size();i++)
		{
			bs.get(i).setX((int)(Math.random()*900));
			bs.get(i).setY((int)(Math.random()*600));
			g.fillOval(bs.get(i).getX(), bs.get(i).getY(), 20, 20);
			System.out.println(Math.random()*600);
			System.out.println(bs.get(i).getX()+"   "+ bs.get(i).getY());
		}
g.setColor(Color.pink);
		for(int i=0;i<bs.size();i++)
		{
			bs.get(i).setX((int)(Math.random()*900));
			bs.get(i).setY((int)(Math.random()*600));
			g.fillOval(bs.get(i).getX(), bs.get(i).getY(), 20, 20);
			System.out.println(Math.random()*600);
			System.out.println(bs.get(i).getX()+"   "+ bs.get(i).getY());
		}
	}
@Override
	public void run() {
		// TODO 自动生成的方法存根
		while(true)
		{
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}
			this.repaint();
			timesDown--;
			if(timesDown==-1)
				timesDown=10;
		}
	
	}
}

class Ball {
	int x,y;
	int speed=1;
	public Ball(){}
	public Ball(int x,int y)
	{
		this.x=x;
		this.y=y;
	}
	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值