要建立一个Shape类,派生出圆,方等类。关键是怎么调用graphic, 参数是什么。怎么调用,类创建好了
import java.awt.Graphics;class Circle extends Point
{
protected int r;
public Circle(int x,int y,int r)
{
super(x,y);
this.r=r;
}
}
比如是这个
在主类里怎么调用
import java.awt.Graphics;class Circle extends Point
{
protected int r;
public Circle(int x,int y,int r)
{
super(x,y);
this.r=r;
}
}
比如是这个
在主类里怎么调用
{
private Shape shp = new Shape; shp = new Circle(0, 0, 0);
}public void paint(Graphics g)
{
shp.draw(g);
}
LZ的类改成import java.awt.Graphics;class Circle extends Point
{
protected int r;
public Circle(int x,int y,int r)
{
super(x,y);
this.r=r;
}
public void draw(Graphics g)
{
g.drawOval((x-r), (y-r), (2 * r), (2 * r));
}
}就行了