As with most programs, there must be a main controller. This is no different.
We will use the main()
function to do this:
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:
new
keywordHere, 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.
Instantiation happens with the keyword new
and you can see that here in TOW places:
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