Java Graphics 图形绘制(2)

 

g.drawArc(10,40,90,50,0,180); // 画圆弧线 g.drawArc(100,40,90,50,180,180); // 画圆弧线 g.setColor(Color.yellow); g.fillArc(10,100,40,40,0,-270); // 填充缺右上角的四分之三的椭圆 g.setColor(Color.green); g.fillArc(60,110,110,60,-90,-270); // 填充缺左下角的四分之三的椭圆 

 
 

画多边形

/** * 绘制一个由 x 和 y 坐标数组定义的闭合多边形。每对 (x, y) 坐标定义一个点。 */ public abstract void drawPolygon(int[] xPoints, int[] yPoints, int nPoints); /** * 填充由 x 和 y 坐标数组定义的闭合多边形。 */ public abstract void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)

int px[] = { 210, 220, 270, 250, 240 }; int py[] = { 220, 250, 300, 270, 220 }; g.drawPolygon(px, py, px.length); 

画字符串

public abstract void drawString(String str, int x, int y) 使用此图形上下文的当前字体和颜色绘制由指定 string 给定的文本。最左侧字符的基线位于此图形上下文坐标系的 (x, y) 位置处。   参数:   str - 要绘制的 string。   x - x 坐标。   y - y 坐标。

g.setColor(Color.GREEN); g.setFont(new Font("楷体", Font.BOLD, 20)); g.drawString("使用画笔绘制的字符串内容", 220, 345); 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/249741cf026cc1c7c3420d8fbd876ae5.html