Practice pieces


Drawing

This task is mainly a matter of making a paint method that draws on the canvas object given. The tricky bit is drawing lines between subsequent points.


Hints:

First off, make a paint method in the Analyst class. In this, get hold of the Canvas object's graphics context and use it to drawString("Hello World", 30,30); to the canvas to check you can get something drawn. Remember that if you ask for a Graphics object (rather than being sent one) you should dispose of it by calling its finalize() method.

Next, add the code to print the line between each point. You'll need two sets of x,y coordinates to draw the line, so you'll need two lines from the file / two rows from the array. Start by just drawing the first line, then put the code in a loop to draw all lines. You'll need to think through the stopping condition on the loop. You'll also need to cast the values from double (which the Storage class uses) to ints.

If you need more help, here's the answers (or one option, anyhow).