应朋友之约作一个雪花飞舞的场面.
这是俺第一个Java程序,
放在这儿留个纪念吧.俺不怕见笑.
再次感谢YoYoYo.
import java.awt.*;
import java.applet.*;
import java.awt.image.*;
import java.awt.event.*;
import java.net.*;
public class snoi extends Applet implements Runnable,MouseListener {
Image images,offScreenImage;
Graphics offScreen;
intdo
tx[],doty[];
Thread thread;
public void init() {
images = getImage(getDocumentBase(), "chinaweb.jpg");
addMouseListener(this);
this.setCursor(new Cursor(Cursor.HAND_CURSOR));
offScreenImage=createImage(778,450);
offScreen=offScreenImage.getGraphics();
dotx = new int[300];
doty = new int[300];
for(int i=0;
i<300;
i++){
dotx = (int)(778*Math.random());
doty = (int)(450*Math.random());
}
}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseClicked(MouseEvent e){
try {getAppletContext().showDocument(new URL(getDocumentBase(),"main.htm"));
}
catch (MalformedURLException err) {}
}
public void start() {(thread = new Thread(this)).start();}
public void stop() {thread = null;
}
public void update(Graphics g) {paint( g );}
public void paint(Graphics g) {
offScreen.drawImage(images, 0, 0, this);
offScreen.setColor(Color.white);
for(int i=0;
i<300;
i++){
offScreen.drawLine(dotx,doty,dotx,doty);
int rand = (int)(2*Math.random());
if (rand == 1)do
tx =do
tx+2;
else
do
tx =do
tx-2;
doty =do
ty+2;
if ((dotx > 778)||(dotx < 0)) {dotx = 0;doty = (int)(450*Math.random());}
if (doty > 450) {doty = 0;dotx = (int)(778*Math.random());}
}
g.drawImage(offScreenImage, 0, 0, this);
}
public void run() {
int delay = 100;
try {
while (thread == Thread.currentThread()) {repaint();
Thread.sleep(delay);}
} catch (Exception e) {}
}
}