- Some aspects of Java program structure.
- Each program is constructed by completing a class
definition.
- A class definition consists of a class header followed
by a collection of
- variable declarations
- method definitions
grouped within curly braces.
- A method definition consists of a method header followed
by a list of statements grouped by curly braces.
- A methods name determines when the statements in the
method are preformed. For example, the following names
associate instructions with user actions:
- onMousePress
- onMouseRelease
- onMouseClick
- onMouseEnter
- onMouseExit
- onMouseMove
- onMouseDrag
- begin
- There are (at least) three kinds of statements:
- constructions (new ... ),
- method invocations ( canvas.clear() ),
- assignments ( uptext = ... )
- Discussion of variables and how they can be used as labels.
- Class Examples:
- A class that first draws the words "up" and
"down" on the screen, with the word "up" in red and "down"
in gray. When the mouse is depressed, reverse the colors.
(this uses instance variables). Click on
UpDown
to show the example.
- A class that draws a box wherever the mouse is clicked (using
the Location parameter in the mouse methods).
Click on
Improved MakeBox
to show the example.
- Discussion of constants