JAVA参数画圆
JAVA参数画圆
//画圆一般通过继承JPanel 或者JFrame ,通过调用
//panel或者frame中的Graphics实例完成画图
public void drawCircle(int x,int y,int r,Color color)
{
Graphics g=this.getGraphics()
g.setColor(color)
g.drawOval(x-r, y-r, 2*r, 2*r)
}
其他参数的情况可以重载这个方法,并调用方法中通过设定参数
调用这个public void drawCircle(int x,int y,int r,Color color)方法
来实现
如:
public void drawCircle(int x,int y,int r)
{
this.drawCircle( x, y , r ,Color.Black)
}
public void drawCircle(int x,int y,Color color)
{
Random random=new Random
r=10 random.nextInt(90)
this.drawCircle( x, y, r , color)
}
public void drawCircle(int x,int y)
{
this.drawCircle(x, y, 40 , Color.red)
}