编程绘制一面国旗

public class FlagDemo extends Applet{

    public void paint(Graphics g) {
//下面两行是大五角星的10个拐点的X坐标和Y坐标        
        int xs1[]= {80,85,98,87,92,80,68,73,63,75,80};
        int ys1[]= {40,54,54,62,76,67,76,62,54,54,40};
//下面两行是第一个小五角星的10个拐点的X坐标和Y坐标        
        int xs2[]= {115,117,120,117,118,115,112,113,110,113,115};
        int ys2[]= {34,38,38,40,44,42,44,40,38,38,34};
        g.setColor(Color.red);
        g.fillRect(40, 20, 250, 150);  //填满区域
        g.setColor(Color.yellow);
//fillPolygon(int[] xpoints, int[] ypoints, int npoints)绘制填充区域的多边形,其中参数npoints表示点数        
        Polygon p1=new Polygon(xs1,ys1,10);
        g.fillPolygon(p1);
        Polygon p2=new Polygon(xs2,ys2,10);
        g.fillPolygon(p2);    //绘制小五角星
/**
 * copyArea
public abstract void copyArea(int x,int y, int width,int height,int dx,int dy)
将组件的区域复制到由 dx 和 dy 指定的距离处。此方法从 x 和 y 指定的点向下和向右复制。要将组件的区域向左或向上复制,
请指定负的 dx 或 dy 值。如果源矩形的一部分位于组件边界的外部,或者被另一个窗口或组件遮掩,那么 copyArea 将无法复制相关的像素。
通过调用组件的 paint 方法可刷新被忽略的区域。
参数:x - 源矩形的 x 坐标。y - 源矩形的 y 坐标。width - 源矩形的宽度。height - 源矩形的高度。dx - 复制像素的水平距离。dy - 复制像素的垂直距离。        
 */
        g.copyArea(110, 34, 10, 10, 12, 11);   //复制绘制出第二个小五角星
        g.copyArea(110, 34, 10, 10, 10, 26);   //第三个
        g.copyArea(110, 34, 10, 10, 4, 38);   //第四个
    }
}
 


运行结果:

编程绘制一面国旗