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 ...

Get Learning Java by Building Android Games - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.