回 帖 发 新 帖 刷新版面

主题:麻烦各位帮忙看看我这代码哪里写错了  总说找不到符号

import java.applet.Applet;
import java.awt.*;
public class chap7_6 extends Applet implements Runnable{
    Ball ball[];
    public void init(){
        ball=new Ball[20];
        for(int i=0;i<20;i++){
            ball[i]=new Ball(50+i*10,50+i*10);
        }
        Thread r=new Thread(this);
        r.start();
    }
    public void paint(Graphics g){
        for(int i =0;i<20;i++){
            ball[i].paint(g);
        }
        
    }
    public void run(){
        while (true){
            ball.move();
            try{
                Thread.sleep(100);
            }catch(Exception e){}
            repaint();
        }
    }
}
class Ball{
    int x,y;
    int dx,dy;

    Ball(int x,int y){
        this.x=x;
        this.y=y;
            
        dx=10;
        dy=8;
    }
    public void paint(Graphics g){
        g.fillArc(x,y,50,50,0,360);
    }
    public  void move(){
        x +=dx;
        if (x+50>800 || x<0)
            dx =-dx;
        y +=dy;
        if (y+50>600 || y<0)
            dy =-dy;
    }
}


//<applet code = chap7_6 width =800 height=600></applet>
chap7_6.java:21: 找不到符号
符号: 方法 move()
位置: 类 Ball[]
                        ball.move();
这是哪里错误 希望帮忙看看  先谢谢各位 我是个初学者
                            ^

回复列表 (共2个回复)

沙发

public void run(){
        while (true){
            for(int i=0;i<ball.length;i++)  
                ball[i].move();  //ball是数组,要对其中的某个元素调用move方法。
            try{
                Thread.sleep(100);
            }catch(Exception e){}
            repaint();
        }
}

板凳


反括号多袄
自己检查下

我来回复

您尚未登录,请登录后再回复。点此登录或注册