Graphic Java

As projects get more complicated both the DESIGN and the CODING phases of the software development cycle become more difficult and consequently they take more time and effort. There many coding tricks which programmers use to help them write better code without wasting a lot of time. One of these techniques is creating methods. The student may elect to ignore what follows, but sooner or later the student will need to learn how to create and use methods. It will take a little time now, but it will save a lot of time later!

The following method can be placed between the end of the init method and the beginning of the paint method:

  public void ast(Graphics g, int x, int y){
    g.drawLine(x-10, y, x+10, y);
    g.drawLine(x, y-10, x, y+10);
    g.drawLine(x+7, y+7, x-7, y-7);
    g.drawLine(x+7, y-7, x-7, y+7);
  }
This method can then be called REPEATEDLY within the paint method to create as many asterisks as the student desires. Here are three sample calls to the ast method:
  ast(g, 100, 20);
  ast(g, 85, 50);
  ast(g, 115, 50);
The student should simply copy this much into the standard applet environment and see what is produced. If this still doesn't make sense then the student can always use the old-fashioned, brute-force method of taking on this project.
EXAMPLE: This applet is an approximation of what the student will be expected to create. No code will be offered since the student will need to experiment with the use of the drawLine method to successfully complete this activity.
x

ASSIGNMENT:
Basically, the student will draw a group of asterisks. The student is free to create this image using the brute force method (cranking out a total of 60 calls to drawLine) or the student may use the method outlined at the top of the page.