A beautiful java fireworks Program

Source: Internet
Author: User

 package org. jetic. web. chat; import java. awt. *; import java. applet. *; import java. awt. event. *; import javax. swing. *; public class ChatApplet extends Applet implements MouseListener, Runnable {int x, y; int top, point;/*** initializes the variables and colors of the Applet. */Public void init () {x = 0; y = 0; // set the background Color to black setBackground (Color. black); addMouseListener (this);} public void paint (Graphics g) {}/ *** enables the program to run as an application. */Public static void main (String args []) {ChatApplet applet = new ChatApplet (); JFrame frame = new JFrame ("TextAreaNew"); frame. addWindowListener (new WindowAdapter () {public void windowClosing (invalid wevent e) {System. exit (0) ;}}); frame. getContentPane (). add (applet, BorderLayout. CENTER); frame. setSize (800,400); applet. init (); applet. start (); frame. setVisible (true);}/*** program main thread, draw a fireworks. */Public void run () {// variable initialize Graphics g1; g1 = getGraphics (); int y_move, y_click, x_click; int v; x_click = x; y_click = y; y_move = 400; v = 3; int r, g, B; while (y_move> y_click) {g1.setColor (Color. black); g1.fillOval (x_click, y_move, 5, 5); y_move-= 5; r = (int) Math. round (Math. random () * 4321) % 200) + 55; g = (int) Math. round (Math. random () * 4321) % 200) + 55; B = (int) Math. round (Math. random () * 4321) % 200) + 55; g1.setColor (new Color (r, g, B); g1.fillOval (x_click, y_move, 5, 5); for (int j = 0; j <= 10; j ++) {if (r> 55) r-= 20; if (g> 55) g-= 20; if (B> 55) B-= 20; g1.setColor (new Color (r, g, B); g1.fillOval (x_click, y_move + j * 5, 5);} g1.setColor (Color. black); g1.fillOval (x_click, y_move + 5*10, 5, 5); try {Thread. currentThread (). sleep (v ++);} catch (InterruptedException e) {}} for (int j = 12; j> = 0; j --) {g1.setColor (Color. black); g1.fillOval (x_click, y_move + (j * 5), 5); try {Thread. currentThread (). sleep (v ++)/3);} catch (InterruptedException e) {}} y_move = 400; g1.setColor (Color. black); while (y_move> y_click) {g1.fillOval (x_click-2, y_move, 9, 5); y_move-= 5;} v = 15; for (int I = 0; I <= 25; I ++) {r = (int) Math. round (Math. random () * 4321) % 200) + 55; g = (int) Math. round (Math. random () * 4321) % 200) + 55; B = (int) Math. Round (Math. random () * 4321) % 200) + 55; g1.setColor (new Color (r, g, B); g1.drawOval (x_click-3 * I, y_click-3 * I, 6 * I, 6 * I); if (I <23) {g1.drawOval (x_click-3 * (I + 1), y_click-3 * (I + 1), 6 * (I + 1 ), 6 * (I + 1); g1.drawOval (x_click-3 * (I + 2), y_click-3 * (I + 2), 6 * (I + 2 ), 6 * (I + 2);} try {Thread. currentThread (). sleep (v ++);} catch (InterruptedException e) {} g1.setColor (Color. black); g1.drawOval (x_click-3 * I, y_click-3 * I, 6 * I, 6 * I );}} /*** Listens to mouse events. * Click the mouse to listen to the event. * When you press the mouse, a new thread is generated. */Public void mousePressed (MouseEvent e) {x = e. getX (); y = e. getY (); Thread one; one = new Thread (this); one. start (); one = null;}/*** implements the MouseListener method. Is an empty method. */Public void mouseReleased (MouseEvent e) {}/ *** implements the method in MouseListener. Is an empty method. */Public void mouseEntered (MouseEvent e) {}/ *** implements the MouseListener method. Is an empty method. */Public void mouseExited (MouseEvent e) {}/ *** implements the method in MouseListener. Is an empty method. */Public void mouseClicked (MouseEvent e ){}}

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.