这个是我那个画圆的类
public class MyCircle implements Drawable
{
Point m_pCenter;
double m_dRadius;
int m_width;
public MyCircle(Point p,double r)
{
m_pCenter.x=p.x-(int)r;
m_pCenter.y=p.y-(int)r;
m_dRadius=r;
m_width=(int)m_dRadius;
}
public MyCircle(Point p,int width)
{
m_width=width;
m_pCenter=p;
}
Point getCenter()
{
return m_pCenter;
}
double getRadius()
{
return m_dRadius;
}
double calculatePerimeter()
{
return 2*Math.PI*m_dRadius;
}
double calculateArea()
{
return Math.PI*m_dRadius*m_dRadius;
}
boolean drawMyCircle(Graphics g)
{
g.drawOval(m_pCenter.x,m_pCenter.y,m_width,m_width);
return true;
}}
public class MyCircle implements Drawable
{
Point m_pCenter;
double m_dRadius;
int m_width;
public MyCircle(Point p,double r)
{
m_pCenter.x=p.x-(int)r;
m_pCenter.y=p.y-(int)r;
m_dRadius=r;
m_width=(int)m_dRadius;
}
public MyCircle(Point p,int width)
{
m_width=width;
m_pCenter=p;
}
Point getCenter()
{
return m_pCenter;
}
double getRadius()
{
return m_dRadius;
}
double calculatePerimeter()
{
return 2*Math.PI*m_dRadius;
}
double calculateArea()
{
return Math.PI*m_dRadius*m_dRadius;
}
boolean drawMyCircle(Graphics g)
{
g.drawOval(m_pCenter.x,m_pCenter.y,m_width,m_width);
return true;
}}
public interface Drawable
{
abstract drawShape();
}
Drawable 是一个interface,里面的method都是abstract
MyCirle与MyRectangle都是implement Drawable,如果这两个类本身不是abstract,那么这两个类里面必需实现drawShape()这个方法。
aaa.drawShape();就行了
{
void drawShape();
}