list.add(1);public class Dog{
Dog dog=new Dog(“a”); Dog dog1=new Dog(“b”);Dog dog2=new Dog(“c”); list.add(dog);list.add(dog1); //集合的遍历 for (int i =0; i<list.size(); i++){ Dog d=list.gte(i); d.eat(); int x,y,d; //设置小球颜色 Color ballColor; //构造方法初始化属性 public Ball(int x,int y,int d,Color ball super() ; this.x=x; this.y=y;this.d=d; this.ballColor =ballColor; } //创建小球对象 public MballJPanel(){ //添加小球的方法 public void addBall(){ int x=(int) (Math.random()*750);int y=(int) (Math.random()*550);int d=(int) (Math.random()*50+1);int r=(int) (Math.random()*255); Color baColor=new Color(r.g. b); Ball ball =new Ball(x,y,d,baColor); balls.add(ball);