雪の結晶〜

**注:
1) これは Java プロジェクトです。Maven を使用してこの jlayer-1.0.1.jar をダウンロードし
、環境へのパスを構築します。
2) これらの写真用に新しい画像と音楽フォルダーを作成できます。在这里插入代码片

public class Snow extends JDialog{//主窗口
private staticfinallongserialVersionUID = -6073107021198223228L;
//获取画面分辨率
public Final static int width = (int) java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;
public Final static int Height = (int) java.awt.Toolkit.getDefaultToolkit().getScreenSize().height;
public Final static String property = System.getProperty(“user.dir”);
public static void main(String[] args) { new Snow().setVisible(true); { System.out.println(“你好~”+property);を試してください。new Player(new BufferedInputStream(new FileInputStream(new File(property+File.separator+“music”+File.separator+“成都.mp3”)))).play(); } catch (FileNotFoundException e) {





e.printStackTrace();
} catch (JavaLayerException e) { e.printStackTrace(); } } public Snow(){ this.setLocation(0,0);//position this.setSize(Width, Height);//size 、サイズは画面の解像度ですthis.setUndecorated(true);//最大化および最小化された列を非表示にします。それが何と呼ばれるか思い出せませんthis.setAlwaysOnTop(true);//ウィンドウは常に前面に表示されますthis.setDefaultCloseOperation ( 0);// Alt+F4 を押して hua を閉じることを禁止しますhua=new hua(); this.add(hua); AWTUtilities.setWindowOpaque(this, false); // 実現するには jre1.7 バージョンを使用することをお勧めします透明なウィンドウ} }













class hua extends JPanelimplements Runnable{///画布
private staticfinallongserialVersionUID=-2986761287590314088L;
public static ArrayListlist=new ArrayList();
プライベート BufferedImage 画像;
public Final static String property = System.getProperty(“user.dir”);
public hua(){ try { img=ImageIO.read(new File(property+File.separator+“image”+File.separator+“orange.jpg”)); } catch (IOException e) { e.printStackTrace(); }//追加雪花图片this.setOpaque(false);//透明なnew Thread(this).start();//启アニメーション程} @Override public voidPaint(Graphics g) { super.paint(g) ; for(int i=0;i<list.size();i++){ xue x=list.get(i);













g.drawImage(img, (int)xx, (int)xy, xw, xh, null);
}
}

@Override
public void run() { int fps=150;//1 秒あたりのフレーム数int time=1000/fps; int ii=0; while(true){ long a=System.currentTimeMillis(); if(ii> 3 ){ new xue(); ii=0; } ii++; for(int i=0;i<list.size();i++){// の実行メソッドlist.get(i).run()を呼び出します。すべての雪の結晶; } repaint();//雪をペイントlong b=System.currentTimeMillis(); long c=ba; if(time-c>0) try {Thread.sleep(time-c);} catch (InterruptedException e ) { e.printStackTrace();} } } }




















class xue{//雪0
public int w,h;
public float x,y,sdx,sdy;
public xue(){ w=h=(int)(Math.random()*20+10);//ランダムサイズsdx=(float) (Math.random()*0.7+0.3);//x軸移動速度sdy=(float) (Math.random()*0.4+0.3);//y軸移動速度/ /snowflake 場所は画面の右上にのみ表示されますdouble gailv=(double)(Snow.Width+Snow.Height)/Snow.Width-1; if(Math.random()<gailv){//Snowflakes画面の上部にありますy=-h; x=(int)(Math.random() Snow.Width); } else{//雪の結晶は画面の右側にありますx=Snow.Width; y= (int)(Math.random() Snow.Height); } hua.list.add(this);//コレクションに追加} public void run(){//雪の結晶の動き//雪の結晶が画面範囲を超えた場合、コレクションから削除します

















if(x+w<0||y>Snow.Height||x+w<0||y>Snow.Height){ hua.list.remove(this); y +=sdy; x-=sdx; } }





おすすめ

転載: blog.csdn.net/qq_40077806/article/details/89888666