圈不动Java小程序

时间:2014-06-19 18:08:40

标签: java applet awt

我想让我的圈子移动,所以我可以继续开发我的小applet游戏,但由于某种原因,它不动,我无法弄清楚原因。

public class StartingPonit extends Applet implements Runnable{

    int x = 0;
    int y = 0;
    int dx = 1;
    int dy = 1;
    int radis = 20;
    private Image i;
    private Graphics doubleG;

    @Override
    public void init() {
        setSize(800,600);

    }
        @Override
    public void start() {
        Thread thread = new Thread(this);
        thread.start();  // thread info;
    }
        @Override
    public void run() {
        x =+ dx;
        y =+ dy;
        //thread info
        while (true){
        repaint();
        try {
            Thread.sleep(17);
        } catch (InterruptedException ex) {
            Logger.getLogger(StartingPonit.class.getName()).log(Level.SEVERE, null, ex);
        }
        }
    }
        @Override
    public void stop() {

    }
    public void destory() {

    }
    @Override
    public void update(Graphics g) {
        if(i == null){
            i = createImage(this.getSize().width,getSize().height); //double bbuffering
            doubleG = i.getGraphics();
       }
        doubleG.setColor(getBackground());
        doubleG.fillRect(0,0, this.getSize().width,this.getSize().height);

        doubleG.setColor(getForeground());
        paint(doubleG);

        g.drawImage(i, 0, 0, this);
    }
    @Override
        public void paint(Graphics g) {
            g.setColor(Color.BLACK);
            g.fillOval(x-radis, y-radis, radis*2, radis*2); //size of object

    } 

}

2 个答案:

答案 0 :(得分:0)

您没有在循环中更新xy

//thread info
while (true){   
    repaint();
     x += dx;
     y += dy;
   //rest the same
}

答案 1 :(得分:0)

你也有误导毁灭() - public void destory() - 应该是public void destroy()