效果:
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class App extends Frame {
//背景
int b1x[] = {0, 666, 666, 0};
int b1y[] = {00, 0, 666, 666};
Thread thread;
int count = 8;//个数
App() {
setLayout(new FlowLayout());
setTitle("1024快乐");
setSize(666, 666);
setVisible(true);
setLocation(850,100);
}
public void paint(Graphics g) {
g.setColor(Color.BLACK); // 描画颜色
g.fillPolygon(b1x, b1y, 4); // 描画
while (true) {
g.setColor(Color.BLACK); // 描画颜色
g.fillPolygon(b1x, b1y, 4); // 描画
int flowerx = (int) (Math.random() * 666);//x坐标
int flowery = 100 + (int) (Math.random() * 300); //最终y坐标
int movey = 666;//弹移动变量
while (movey >= flowery)//当
{
g.setColor(Color.BLACK); // 描画颜色
g.fillPolygon(b1x, b1y, 4); // 描画
g.setColor(Color.WHITE); // 弹颜色白色
g.drawString("1024",flowerx,movey);
try {
Thread.sleep(20);//延时
} catch (InterruptedException e) {
e.printStackTrace();
}
//用黑色抹去弹踪迹
g.setColor(Color.BLACK);
g.drawString("1024",flowerx,movey + 1200 / flowery);
movey -= 1200 / flowery;//向上移动幅度
}
g.setColor(Color.WHITE); // 弹颜色白色
g.fillOval(flowerx, flowery, 1600 / flowery, 1600 / flowery);//弹大小
try {
Thread.sleep(30);//延时
} catch (InterruptedException e) {
e.printStackTrace();
}
//抹去弹
g.setColor(Color.BLACK); // 描画颜色
g.fillPolygon(b1x, b1y, 4); // 描画
//炸出以弹终点坐标为圆心的40个小
for (int i = 0; i < 10; i++) {//
int r = 3 + (int) (Math.random() * 400 / flowery);//花骨朵半径
//右下象限
Color c1 = new Color((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255));//花骨朵颜色
g.setColor(c1);
g.fillOval(flowerx + (int) (Math.random() * r * 50), flowery + (int) (Math.random() * r * 50), r, r);
g.drawString("1024",flowerx + (int) (Math.random() * r * 50), flowery + (int) (Math.random() * r * 50));
//左上象限
Color c2 = new Color((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255));//花骨朵颜色
g.setColor(c2);
g.fillOval(flowerx - (int) (Math.random() * r * 50), flowery - (int) (Math.random() * r * 50), r, r);
g.drawString("8",flowerx - (int) (Math.random() * r * 50), flowery - (int) (Math.random() * r * 50));
//左下象限
Color c3 = new Color((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255));//花骨朵颜色
g.setColor(c3);
g.fillOval(flowerx - (int) (Math.random() * r * 50), flowery + (int) (Math.random() * r * 50), r, r);
g.drawString("16",flowerx - (int) (Math.random() * r * 50), flowery + (int) (Math.random() * r * 50));
//右上象限
Color c4 = new Color((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255));//花骨朵颜色
g.setColor(c4);
g.fillOval(flowerx + (int) (Math.random() * r * 50), flowery - (int) (Math.random() * r * 50), r, r);
g.drawString("32",flowerx + (int) (Math.random() * r * 50), flowery - (int) (Math.random() * r * 50));
}
try {
Thread.sleep(600);//延时
} catch (InterruptedException e) {
e.printStackTrace();
}
count--;//减1
if (count <= 0) break;//放完退出循环
}
System.exit(0); //退出窗体
}
class WinAdapter extends WindowAdapter {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
}
public static void main(String[] args) {
App f = new App();
}
}