Using Java to implement snow conditions

Source: Internet
Author: User

The above is the implementation of the situation, the following code, the implementation should be dynamic, interested people can run their own try:

Import Javax.swing.JFrame;
Import Javax.swing.JPanel;
Import Java.awt.Graphics;
Import Java.awt.Color;
Import Java.awt.Font;
public class Mysnow extends JFrame {
Public Mysnow () {
Snow s=new Snow ();
Thread t=new thread (s);
T.start ();

This.add (s);
This.setresizable (FALSE);
This.setsize (1366,768);
This.setdefaultcloseoperation (Jframe.exit_on_close);
}
public static void Main (string[] args) {
Mysnow ms=new Mysnow ();
Ms.setvisible (TRUE);
}
}
Class Snow extends JPanel implements runnable{
Private int[] x;
Private int[] y;
Public Snow () {
X=new int[300];
Y=new int[300];
This.setbackground (Color.Black);
}
public void Paint (Graphics g) {
Super.paint (g);
G.setcolor (Color.White);
G.setfont (New Font ("Italic", font.bold,30));
for (int i=0;i<300;i++) {
x[i]= (int) (Math.random () *1366);
y[i]= (int) (Math.random () *768);
}
for (int i=0;i<300;i++) {
g.DrawString ("*", x[i], y[i]);
}
}
public void Run () {
while (true) {
for (int i=0;i<300;i++) {
y[i]++;
if (y[i]>768) {
y[i]=0;
}
}
try{
Thread.Sleep (800);
}catch (Exception e) {

}
This.repaint ();
}
}
}

Using Java to implement snow conditions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.