Article View: cn.bbs.comp.lang.java
Article #12161���� �����Applet������ʲô����
From: �Ұ�Java
Date: Fri, 06 Aug 2004 08:54
Date: Fri, 06 Aug 2004 08:54
74 lines
2679 bytes
2679 bytes
import java.awt.*;
import java.applet.*;
public class Move extends Applet implements Runnable {
int x,y,moveX,moveY,width,height;
Thread newThread;
Image offScreen;
Graphics drawOffScreen;
public void init() {
x = 0;
y = 0;
moveX = 2;
moveY = 3;
width = getSize().width;
height = getSize().height;
offScreen = createImage(width,height);
drawOffScreen = offScreen.getGraphics();
}
public void start() {
newThread = new Thread(this);
newThread.start();
}
public void stop() {
newThread = null;
}
public void paint(Graphics g) {
drawOffScreen.setColor(Color.black);
drawOffScreen.fillRect(0,0,width,height);
drawOffScreen.setColor(Color.white);
drawOffScreen.fillOval(0,0,30,30);
g.drawImage(offScreen,0,0,30,40,this);
}
public void update(Graphics g) {
paint(g);
}
public void run() {
while(newThread != null) {
repaint();
try {
Thread.sleep(50);
}catch (InterruptedException e) {
System.out.println("����");
}
x = x + moveX;
y = y = moveY;
if(x >= (width - 30)) {
x = width -30;
moveX = -moveX;
}
if(x <= 0) {
x = 0;
moveX = -moveX;
}
if(y >= (height - 30)) {
y = y - 30;
moveY = - moveY;
}
if(y <=0) {
y = 0;
moveY = -moveY;
}
}
}
}
--
[m[1;32m�� ��Դ:����ˮ˼Դ bbs.sjtu.edu.cn��[FROM: 202.192.159.41][m
Technical Details
Message-ID:
<4DW7ha$A4P@bbs.sjtu.edu.cn>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news3.optonline.net!news.bylinux.net!maily.cic.tsinghua.edu.cn!netnews.sdu.edu.cn!SJTUShow Full Headers
Complete Article Headers
X-Google-Thread: f6cb0,8fea7911367c9ac,start X-Google-Attributes: gidf6cb0,public X-Google-Language: ENGLISH,GB Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news3.optonline.net!news.bylinux.net!maily.cic.tsinghua.edu.cn!netnews.sdu.edu.cn!SJTU From: Avent.bbs@bbs.sjtu.edu.cn (�Ұ�Java) Newsgroups: cn.bbs.comp.lang.java Subject: ���� �����Applet������ʲô���� Date: 06 Aug 2004 08:54:36 GMT Organization: ��ˮ˼Դ Message-ID: <4DW7ha$A4P@bbs.sjtu.edu.cn> Mime-Version: 1.0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: 8bit X-Filename: Java/M.1091782452.A Lines: 74