Java流星雨

package abc;

import java.io.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;

public class 流星雨 extends JFrame implements Runnable {
    Canvas canvas = new Canvas();   
    public 流星雨() {
        int height = Toolkit.getDefaultToolkit().getScreenSize().height;
        int wight = Toolkit.getDefaultToolkit().getScreenSize().width;
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setSize(wight,height);
        //this.setLocation(-1, 0);
        canvas.setSize(this.getSize().width, this.getSize().height);
        this.getContentPane().add(canvas, BorderLayout.CENTER);
        this.pack();
        canvas.setBackground(Color.BLACK);
        this.setVisible(true);
    }
    ArrayList<Rain> rainlist = new ArrayList<流星雨.Rain>();
    //ArrayList<Rain> rr = new ArrayList(); 
    //ArrayList<Rain> xr = new ArrayList(); 
    Random random = new Random();  
    public void paint() throws IOException{
        Image image = createImage(this.getSize().width, this.getSize().height);
        Graphics g = image.getGraphics();
        g.setColor(Color.black);
        g.fillRect(0, 0, this.getSize().width, this.getSize().height);
        for(int i = 0; i < 10; i++){
            rainlist.add(new Rain(getSize().width/4+random.nextInt()%(getSize().width+getSize().width/4)
                ,getSize().width/4+random.nextInt()%(getSize().width+getSize().width/4)
                        ,getSize().width/4+random.nextInt()%(getSize().width+getSize().width/4)));
        }
        for(int i = 0; i < rainlist.size(); ){
            rainlist.get(i).paint(g);
           // rr.get(i).paint(g);     
            if(rainlist.get(i).y > this.getSize().height){
                rainlist.remove(i);
            } else {
                i++;
            }
        }
        canvas.getGraphics().drawImage(image, 0, 0, null);
    }  
    class Rain {    
        int ci = 0;
        int ci1 = 0;
        public int x, y, a, b,c,d;
        public Rain(int x,int a,int c){
            this.x = x;
            this.y = 0;
            this.a = a;
            this.b = 0;
            this.c = c;
            this.d = 0;
        }    
        public void paint(Graphics g) throws IOException{
            //黑色圆遮掉白色圆,形成月亮
            g.setColor(Color.white); 
              g.fillOval(20, 20, 60, 60); 
              g.setColor(Color.BLACK); 
              g.fillOval(0, 0, 60, 60); 
            int R=(int)(Math.random()*255);
            int G=(int)(Math.random()*255);
            int B=(int)(Math.random()*255);
            //偶尔快的流星
            int xing =(int)(Math.random()*50 + 1);
            int xing1 = (int)(Math.random()*50 + 1);
            int xing2 = (int)(Math.random()*50 + 1);
            if(xing == 20 && xing1 > 5) {
            g.setFont(new Font("",Font.BOLD,20));
            g.setColor(new Color(250,250,250));
              g.drawString("★", 30, 20);
            g.setColor(new Color(180,180,180));
              g.drawString("★", 30, 20);        
            }
          /* g.setColor(new Color(220,220,220));
            g.drawString("★", 20, 340);*/   
            if(xing == 1 && xing1 == 5 && xing2 == 5) {
            for(int i = 0 ; i < 10 ;i++) {
                /*ThreadLocalRandom tt = ThreadLocalRandom.current();
                int v = tt.nextInt(300);
                int vv = tt.nextInt(1080);*/
                  g.setColor(new Color(160,160,160));
                  g.drawString("★", 100, 100);
                  g.setColor(new Color(220,220,220));
                  g.drawString("★", 100, 100);
                //  
                  g.setColor(new Color(160,160,160));
                  g.drawString("★", 800, 34);
                  g.setColor(new Color(220,220,220));
                  g.drawString("★", 800, 34);
                //
                  g.setColor(new Color(160,160,160));
                  g.drawString("★", 300, 20);
                  g.setColor(new Color(220,220,220));
                  g.drawString("★", 300, 20);
            }
            }
            //流星雨
            g.setColor(new Color(R,G,B));
            //g.drawOval(x-2, y-3, 5, 4);
            g.setColor(Color.white);
            g.fillOval(x-2, y-2, 4, 4);
            g.setColor(new Color(200,200,200));
            g.drawLine(x+19,y-20, x, y);
            x-=10;
            y+=10;       
            //文字描述
            if(xing == 1 && xing1 == 5 && xing2 >= 40) {
                g.setColor(Color.white);
                g.fillOval(a-2, b-2, 4, 4);
                g.setColor(new Color(200,200,200));
                g.drawLine(a-850,b+1000, a, b);
                a-=10;
                b+=10;           
                }
            int c = 300 ;
            int d = 100;
            String zi = "我希望加入党组织,"
                    + "绝不是为了捞点‘政治资本’";  
            ci = ci +20;       
            if(ci == 700) { 
            String[] f = zi.split(",");
                for(int i = 0 ; i < f.length ; i++) {
                g.setColor(new Color(255,255,255));
                g.setFont(new Font("宋体",Font.BOLD,20));
                g.drawString(f[i], c, d);
                c+=20;      
                } 
           }      
            if(ci == 1000) {    
                c -= 20;
                d += 50;
                String zi1 = "也不是为了升官发财,"
                        + "我只是想以一个党员的身份严格要求自己";
                String[] f1 = zi1.split(",");
                for(int i = 0 ; i < f1.length ; i++) {
                g.setColor(new Color(255,255,255));
                g.setFont(new Font("宋体",Font.BOLD,20));
                g.drawString(f1[i], c, d);
                c+=20;      
                }             
            }     
           //ci1+=20;
           if(ci == 1300) {
                   d += 100;
                   c -= 30;
                   String zi2 = "为党和人民的利益,"
                           +"贡献自己的一切,甚至生命";
                String[] f2 = zi2.split(",");
                for(int i = 0 ; i < f2.length ; i++) {
                g.setColor(new Color(255,255,255));
                g.setFont(new Font("宋体",Font.BOLD,20));
                g.drawString(f2[i], c, d);
                c+=20;          
            }  
            } 
           
           
        }
        }       
    public void run(){
        int i =0;
        while(true){
            try {i+=20;
                if(i == 1600){File file = new File("D:\\eclipse素材库\\手指舞.mp4");
                 Process p = Runtime.getRuntime().exec("C:\\Program Files (x86)\\IQIYI Video\\QyClient.exe " +file); //.exe后面留有空格
                }
                paint();
               // paint1();
                Thread.sleep(30);          
            } catch (Exception e) {
                e.printStackTrace();
                           
            }
        }  
    }
    public static void main(String[] args) throws IOException {
        (new Thread(new 流星雨())).start();
           }
}


 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

离陌殇殃

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值