🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.lang.java
Article #12171

Re: ���� �����Applet������ʲô����

#12171
From: �տ�
Date: Sat, 07 Aug 2004 03:06
98 lines
3958 bytes
��ij���Ӧ������ʵ��һ��С������Ļ����ײ�����ذɡ�������м�����������y = y 
= moveY;Ӧ����y = y �� moveY;ƴд������������в���˫���弼����ֹ������˸����
��ͼ��Ĵ����ͻ��Ʋ�Ӧ����init���������У���Ӧ����update���������С����Ҳ����
���ص��߼��������ڻ���С��ʱ��ʹ�õķ�����drawOffScreen.fillOval(0,0,30,30);ÿ
�ζ�����Ļ��˻���һ���뾶Ϊ30��Բ������run����������������Բ��λ�õĸı�����ʲ
ô�����أ��Dz���Ӧ������д�أ�g.fillOval(x,y,30,30);��������������������޸�
��
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;

    }
    public void start() {
        newThread = new Thread(this);
        newThread.start();
    }
    public void stop() {
       newThread = null;
    }

    public void paint(Graphics g) {
      g.setColor(Color.white);
       g.fillOval(x,y,30,30);


    }
    public void update(Graphics g) {
      if(offScreen==null){
        width = this.getSize().width;
        height = this.getSize().height;
        offScreen = createImage(width,height);
        drawOffScreen = offScreen.getGraphics();
      }
      drawOffScreen.setColor(Color.black);
       drawOffScreen.fillRect(0,0,width,height);



        paint(drawOffScreen);
        g.drawImage(offScreen,0,0,this);
    }
    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;
                }

        }
    }
}



�� �� Avent.bbs@bbs.sjtu.edu.cn (�Ұ�Java) �Ĵ������ᵽ: ��
: ...................



--
    �Ķ���Զ����δ���� 
�����������ںܲ����⣻ 
����һ�ж���˲�䣬һ�ж����ȥ�� 
�������ǹ�ȥ�˵Ķ����Ϊ���õĻ��䡣

�� ��Դ:����ɽ��ˮվ http://bbs.neu.edu.cn��[FROM: 202.118.0.200]
Technical Details
Message-ID: <4DWaHO$EDv@bbs.neu.edu.cn>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!newsfeed.media.kyoto-u.ac.jp!news.neu.edu.cn!NEU

Show Full Headers
Complete Article Headers
X-Google-Thread: f6cb0,8fea7911367c9ac
X-Google-Attributes: gidf6cb0,public
X-Google-Language: Chinese,GB
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!newsfeed.media.kyoto-u.ac.jp!news.neu.edu.cn!NEU
From: lifeIlife@bbs.neu.edu.cn (�տ�)
Newsgroups: cn.bbs.comp.lang.java
Subject: Re: ���� �����Applet������ʲô����
Date: 07 Aug 2004 03:06:49 GMT
Organization: ��ɽ��ˮ
Message-ID: <4DWaHO$EDv@bbs.neu.edu.cn>
Mime-Version: 1.0
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: 8bit
X-Filename: java/M.1091848008.30
Lines: 98