Objects and Classes
Good news:
-
Graphics objects easy to understand.
Bad news:
-
Graphics requires some knowledge.
-
Other objects may be harder
to understand.
Think of a button in an applet
(although we cannot implement it yet):
Example:
Bert the Button
-
A Java library contains a class
for buttons
-
we create an individual button,
say "bert" => object
-
bert has methods available
that can modify him
How does this work?
-
You tell Java to create an object
"bert" belonging to the class "Button":
Button bert = new Button("Hi,
I'm Bert");
-
To change the label (and color,
size, etc.) you use a method of class "Button":
bert.setLabel("Hey, you pressed
me! How nice!");
How would you do this without
objects?
?