tree
/*
// Updated by Matt Slaybaugh December 17, 1999
// This is not code anyone should emulate, but at least it works now :)
// Speed, image, and message are hard-coded, change and recompile (jdk 1.0.2) to personalize
*/
import java.awt.*;
import java.applet.*;
import java.lang.*;
public class tree extends Applet implements Runnable {
Image tree;
Image screen;
boolean music = true;
Image snow;
FontMetrics fm;
Font myFont;
int fontsize;
AudioClip sound;
int msg = 0;
MediaTracker track;
Thread test;
String file = "tree.gif";
String message[] = new String[10];
int height;
int width;
int x[] = new int[100];
int y[] = new int[100];
int temp = 0;
double fly;
int l;
int i;
boolean backdrawn = false;
public void init() {
track = new MediaTracker(this);
tree = getImage(getDocumentBase(),file);
track.addImage(tree, 0);
snow = getImage(getDocumentBase(),"snow.gif");
track.addImage(snow,1);
sound = getAudioClip(getDocumentBase(),"sleigh.au");
setBackground(Color.black);
if (screen == null) {screen = createImage(size().width,size().height);}
width = size().width;
height = size().height;
message[0] = "Happy Holidays!";
message[1] = "From JavaBoutique";
message[2] = "Click Image to stop sounds!!";
message[3] = "Happy Solstice!";
message[4] = "Send us your feedback!!";
myFont = new Font("Arial",Font.BOLD,10);
fm = getFontMetrics(myFont);
}
public synchronized void start() {
if (test == null) {
test = new Thread(this);
test.start();
}
}
public synchronized void stop() {
if (test != null) {
sound.stop();
test.stop();
test = null;
}
}
public void run() {
try {
track.waitForAll();
}
catch (InterruptedException e){};
while(true) {
if (!backdrawn) { background(); }
if (backdrawn) {snow(); }
update();
try {
Thread.sleep(120);
}
catch (InterruptedException e){};
}
}
public void update() {
Graphics g = screen.getGraphics();
g.setColor(Color.black);
g.fillRect(0,0,width,height);
g.setColor(Color.yellow);
g.drawImage(tree,(width/2)-35,0,this);
fontsize = fm.stringWidth(message[msg]);
g.setFont(myFont);
g.drawString(message[msg],((width/2)-(fontsize/2)),height-5);
for (l=0;l<30;l++) {
g.drawImage(snow,x[l],y[l],this);
}
g = getGraphics();
g.drawImage(screen,0,0,this);
g.dispose();
}
public void snow() {
temp++;
for (l=0;l<30;l++) {
y[l]+=9;
if (y[l]>100) { y[l]=0;}
}
if (temp>5) {msg++;
if (msg>4) {msg = 0; }
temp = 0;}
}
public void background() {
for (l=0;l<30;l++) {
x[l] =(int)(Math.random()*100)+20;
y[l] =(int)(Math.random()*100);
}
if (music) {sound.loop();}
Graphics g = screen.getGraphics();
g.setColor(Color.black);
g.fillRect(0,0,width,height);
g.drawImage(tree,0,0,this);
backdrawn = true;
update();
}
public boolean mouseDown(Event e, int ms, int my) {
if (!music) { music = true; sound.loop(); return true; }
if (music) {music = false; sound.stop(); return true;}
return true;
}
}
Back to the tree applet page.
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.
|