Using the Canvas class
Let's look at the code and the different stages required to get drawing, and then we can quickly move on to drawing something for real, with the help of the Canvas demo app.
Preparing the objects of classes
Remember, back in Chapter 2, Java – First Contact, that I said the following:
In Java, a blueprint is called a class. When a class is transformed into a real working thing, we call it an object or an instance of the class.
The first step is to turn the classes (blueprints) we need into real working things – objects/instances. This step is analogous to declaring variables.
Important note
We have already done this with the Random
class in the previous chapter and will explore this in more depth in Chapter 8, Object-Oriented Programming.
First, we state the type, which in this case happens to be a class, and then we state the name we would like our working object to have:
// Here are all the objects(instances) // of...