Using the Canvas class
Let's look at the code and the different stages required to get drawing then we can quickly move on to drawing something, for real, with the Canvas demo app.
Preparing the objects of classes
Remember back in chapter two I said this:
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.
Tip
We have already done this with the Random
class in the previous chapter and will explore more deeply 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 classes that we need to do some drawing ImageView myImageView; Bitmap myBlankBitmap; Canvas myCanvas; Paint myPaint;
The previous...