Controlling the "World"

As with most programs, there must be a main controller. This is no different.

We will use the main() function to do this:

The Drawing

Implementation

Below, you can see the function main() that is used to control the "world" for the drawing objects to reside in.

Make note of the following:

  • the subroutine defines creates objects ny using the new keyword
  • the object data is defined as JSON

Controller Routine

Defining the Drawing

Here, we have some JSON data to represent the drawing.

You should see that this data is passed to the drawing class as a parameter (the class has been changed to accomodate this) and this enables the code to remain compact.

Instanitation

Instantiation happens with the keyword new and you can see that here in TOW places:

  • line 12: where the drawing object is instanitated
  • line 39:where the rectangle is instantiated

Adding Objects into the Drawing

In this case a list of rectangle data is looped through to set up the drawing.

The addObject() method enable each new object to be added to the objects attribute in the drawing class and then the canvase is redrawn.





This is a development site to gather together teaching materials for AQA A Level Computer Science. It will be changing and being remodelled throughout this year.

No data is stored on the site but cookies are used to enable the website to function properly.

© 2025 Jay Patel - Dixons Sixth Form Academy, Bradford

Contact: jpatel@dixons6a.com