
Still referring to the code on the previous page, you will see that it refers to
PageNum
. The sketches in the
calculator’s
SKETCH
view are numbered 1, 2, 3…etc. Sketch number 1 is always present but after that only
sketches that have been created are available and the program will crash if you try to access one that does
not exist.
The aplet variable
PageNum
is the pointer to the sketch you want and the actual sketch page itself is called
Page
. Thus the two lines after
ELSE
are telling the program to store the
PLOT
view into the first page of the
SKETCH
view using the command
PLOT
Æ
. This command stores the
PLOT
view into whatever graphics
variable you specify. In this case into
Page
.
The
PLOT
view
must
exist before this can be done or the program will crash. This is the reason for setting up
the flag
G
discussed earlier – by doing that we ensure that this section of code only runs if something has
been plotted. If you run the program and then later change to the
SKETCH
view you will be able to see this
stored image. Finally, the user is presented with two messages which tell them what to do.
The next section contains the code which performs the work in the aplet by setting up a loop which repeats
until the user presses the
ENTER
key to terminate.
The first line before the loop begins assigns initial values to the variables
M
(the gradient) and
C
(the y-
intercept). The
DO…UNTIL
loop which follows (partly in the next section of code) loops through the code
within it until the
ENTER
key is pressed.
Within the loop, the previously stored
SKETCH
view is transferred from storage to the display using
DISPLAY
. The
DISPLAY
command means “transfer to the display screen”. The equation of the current
line is then displayed in the top left corner using the
DISPXY
command which allows you to write text onto
the screen. Two versions are needed to avoid an expression like “y=2x+ -1” and write instead “y=2x-1”.
278