主题:麻烦各位帮忙看看我这代码哪里写错了 总说找不到符号
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();
这是哪里错误 希望帮忙看看 先谢谢各位 我是个初学者
^
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();
这是哪里错误 希望帮忙看看 先谢谢各位 我是个初学者
^