Summary | Heaton Research

Summary

In this article you learned how to display even more Java graphical elements. This chapter focused on lines, pixels, rectangles, ovals and images. You saw that most of the graphical elements have two methods for drawing. They include a method that starts with "draw" that will draw the outline of the graphical element. They also include a method that starts with "fill", which draws a filled in graphical element.

Rectangles and ovals are drawn very similarly. Both graphical elements require you to specify a starting coordinate and a height and width. The rectangle will be drawn with the upper-left corner of the rectangle in that coordinate and the specified height and width. For the oval, Java will draw the oval, which fits just inside of the rectangle specified by the coordinate, height and width.

There are two steps to drawing an image. First the image must be loaded. Secondly, the image must be displayed. There are several steps involved in loading an image. Because of this, I provide the loadImage method that contains all of the needed steps to load the image.

Up to this point we have only drawn stationary images. In the next article we will begin some simple animation.

Copyright 2005-2008 by Heaton Research, Inc.