绘制一个网格的程序

import java.applet.Applet;

import java.awt.*;

public class Exam4_7 extends Applet

{

  public void paint(Graphics g)

  {

    int x0=10,y0=10,dx=15,dy=20,N=15,M=15;

    int x1,x2,y1,y2;

    y1=y0;

    y2=y0+M*dy;

    for(int i=0;i<=N;i++)

    {

      X1=x0+i*dx;

      g.drawLine(x1,y1,x2,y2);

    }

    g.setColor(Color.red);

    x1=x0;

    x2=x0+N*dx;

    for(int j=0;j<=M;j++)

    {

      y1=y0+j*dy;

         g.drawLine(x1,y1,x2,y1);

    }

  }

}

 

posted on 2017-10-02 22:33  小星_log  阅读(340)  评论(0编辑  收藏  举报