advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement


Rain!


Java Source:

//###################################################################
//
// Confetti.java      (C)2000 amIbleeding.com
//
//###################################################################

import java.applet.*;
import java.awt.*;
public class Rain extends Applet implements Runnable
{
	private Thread	 m_snow = null;
	private Image offscreenImage;
	private String m_back = "none";
	private Image backdrop;
	private Graphics offscreenGraphics;
	private Image frame;
	private int xSize;
	private int ySize;
	private int[] colors;
	private int amount;
	private Color[] cl={Color.white, Color.lightGray, Color.gray, Color.darkGray,
		Color.black};
	private String[] cNames={"white","lightGray","gray","darkGray",
		"black"};
    private int delay;
    private int angle;

	public String getAppletInfo()
	{
		return "Name: Confetti\r\n" +
		       "Author: amIbleeding.com\r\n" +
		       "Created with Microsoft Visual J++ Version 1.1";
	}
	public void init()
	{
		String param;
		colors = new int[5];
		amount=0;
		for (int t=0;t<5;t++) {
			param = getParameter(cNames[t]);
			if (param != null)
				colors[t] = Integer.parseInt(param);
		}
		for (int t=0;t<5;t++) {
			int tmp=colors[t];
			colors[t]+=amount;
			amount+=tmp;
		}
		param = getParameter("back");
		if (param != null)
			m_back = param;
		param = getParameter("frame");
		if (param != null)
			frame = getImage(getCodeBase(),param);
		else
			frame=null;
		param = getParameter("delay");
		if (param != null)
			delay= Integer.parseInt(param);
		else
			delay=100;
		param = getParameter("angle");
		if (param != null)
			angle= Integer.parseInt(param);
		else
			angle=0;
		xSize=size().width;
		ySize=size().height;
		backdrop=getImage(getCodeBase(),m_back);
		offscreenImage = createImage(xSize,ySize);
		offscreenGraphics =offscreenImage.getGraphics();
		System.out.println("Confetti (C)2000 amIbleeding.com");
			//{{INIT_CONTROLS
		//}}
}
	public void newimage()
	{	offscreenGraphics.drawImage(backdrop,0,0,xSize,ySize,null);
		offscreenGraphics.setColor(Color.white);
		int onCl=0;
        int x1,y1;
		for(int i=0;i<amount;i++)
		{
			while (i>=colors[onCl]) {
			    onCl++;
    			offscreenGraphics.setColor(cl[onCl]);
			}
            x1=(int)(Math.random()*xSize);
            y1=(int)(Math.random()*ySize);
            offscreenGraphics.drawLine(x1,y1,x1+2*angle,y1+4);
		}
		if (frame != null) {
			offscreenGraphics.drawImage(frame,0,0,xSize,ySize,null);
		}
	}
	public void destroy()
	{
		offscreenGraphics.dispose();
	}
	public void paint(Graphics g)
	{
		g.drawImage(offscreenImage,0,0,this);
	}
	public void update(Graphics g)
	{
		paint(g);
	}
	public void start()
	{
		if (m_snow == null)
		{
			m_snow = new Thread(this);
			m_snow.start();
		}
	}
	public void stop()
	{
		if (m_snow != null)
		{
			m_snow.stop();
			m_snow = null;
		}
	}
	public void run()
	{
		MediaTracker mt = new MediaTracker(this);
		mt.addImage(backdrop,0);
		if (frame!=null) {
			mt.addImage(frame,0);
		}
		try {
			mt.waitForAll();
		} catch (Exception e) {}
		while (true)
		{
			try
			{
				long nw=System.currentTimeMillis();
				newimage();
				repaint();
				long tm=delay-(System.currentTimeMillis()-nw);
				if (tm<10) {tm=10;}
				Thread.sleep(tm);
				newimage();
			}
			catch (InterruptedException e)
			{
				stop();
			}
		}
	}
	//{{DECLARE_CONTROLS
	//}}
}

Back to Rain

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Microsoft RIA Development Center
 IBM Rational Resource Center
 Destination .NET
XML error: not well-formed (invalid token) at line 33
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Facebook Wants to Power Web-Wide Apps
OpenSolaris to Support Facebook, OpenSocial
Sun Takes a Shine to Linux in New Web Stack
MySQL: Back to Its Roots via Sun
Ubuntu Founder: Linux Should Focus on Looks
Intel's Building Blocks Thread Open Source
What Lies Ahead for SOA?
Novell Turns ICE Into Kablink
Is Open Source Development Insecure?
JUNOS: Open, but Not Open Source

View Rendering in Java: Templates Out, Groovy Builders In
Getting the Most from Virtualization
Rational Team Concert
IBM® Rational® Quality Management Open Beta
SIP Application Delivery eKit
Rational Requirements Definition and Management Open Beta:
Download IBM Rational Team Concert
Network Know-how: Finding Shortest Paths
Applying SKOS Concept Schemes
Managing an Agile Software Project

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers