Java Reference
In-Depth Information
Now, the upper-left corner of the rectangle that encloses the circle is just below
the left part of the title bar.
Class Graphics has many methods for drawing. Methods exist for drawing
a line, a rectangle, a filled rectangle (i.e. the whole rectangle and not just its bor-
der is painted), an oval, a filled oval, an arc of an oval, text, and more.
Class Color contains a number of constants, like Color.red . It also con-
tains methods for dealing directly with the RGB (Red-Green-Blue) coloring sys-
tem, which is used for much of the image manipulation in computers.
It will help your progress with Java to type in a class like GraphicsFrame
of Fig. 1.12 and to modify it to draw various lines, rectangles, and so on. You will
not only become familiar with the methods of class Graphics but you will also
gain fluency in the general task of writing method calls, using various expres-
sions as arguments.
If you try to draw a figure like the one in the left margin, draw it first on a
piece of paper, perhaps graph paper, and figure out roughly where each compo-
nent goes.
A footnote on
lesson page 1.5
describes these
methods and
the Color con-
tants.
1.7
Programming style and programming habits
You have now written, debugged, and run a few small programs, and you are
beginning to have a feel for the programming process. The pieces of code you
have written so far are quite small, of course. But by the end of this course you
will have written programs that are perhaps several hundred lines long, and you
may start to find it difficult to remember all the pieces that you have written and
how they fit together. Several good programming habits will help you deal with
this complexity.
There are two goals of these programming habits. First, the habits will make
you a faster and better programmer. Second, other programmers will be able to
read and understand your programs with a minimum of effort.
If you want to continue in computer science, these habits are even more
important than they are for this introductory course. Second, third, and fourth-
year programming courses often have you write thousands of lines of code
In the professional world, creating programs that are readable by others is
even more important. Most programs live a long time and require maintenance
—changes to adapt the code to new and different requirements, upgrades in other
software, new hardware, and so forth. Frequently the author of the program will
not be around when maintenance is required (having been promoted, moved to a
 
Search WWH ::




Custom Search