关于Rectangle 类

wuyan19831013 2004-10-21 08:01:49
这个类import java.awt.*;

public class ball{
protected Rectangle location;
protected double dx;
protected double dy;
protected Color color;

public ball(int x,int y,int r){
location =new Rectangle(x-r,y-r,2*r,2*r);
dx=0;
dy=0;
color=Color.blue;
}

public void setColor(Color newColor){
color=newColor;
}

public void setMotion(double ndx,double ndy){
dx=ndx;
dy=ndy;
}

public int radius(){
return location.width/2;
}

public int x(){
return location.x+radius();
}

public int y(){
return location.y+radius();
}

public double xMotion(){
return dx;
}

public double yMotion(){
return dy;
}

public Rectangle region(){
return location;
}

public void moveTO(int x,int y){
location.setLocation(x,y);
}

public void move(){
location.translate((int)dx,(int)dy);
}

public void paint(Graphics g){
g.setColor(Color.red);
g.fillOval(location.x,location.y,location.width,location.height);
}
}

里面关于location.x,location.y,location.width,location.heigth这几个变量的引用都在编译中显示错了,我搞不清楚为什么??

...全文
214 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyan19831013 2004-10-21
  • 打赏
  • 举报
回复
已解决~~~~~~
wuyan19831013 2004-10-21
  • 打赏
  • 举报
回复
我把location =new Rectangle(x-r,y-r,2*r,2*r);这行提出来重新写了 一下
public class b{
protected Rectangle location;

public b(int x,int y,int r){
location=new Rectangle(x-r,y-r,2*r,2*r);
}
}

编译错误如下:
b.java:5:cannot resolve symbol
symbol:canstructor Rectangle(int,int,int,int)
location:class Rectangle
location=new Rectangle(x-r,y-r,2*r,2*r);
^
就这个~~~~~~~~~~~~~
Tasia 2004-10-21
  • 打赏
  • 举报
回复
location =new Rectangle(x-r,y-r,2*r,2*r);这一行语法是并没有错呀。
把错误信息贴出来看看。
wuyan19831013 2004-10-21
  • 打赏
  • 举报
回复
不好意思,location =new Rectangle(x-r,y-r,2*r,2*r);//这行显示错误
但我看不出为什么?这个才导致后面错了~~~~`````

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧