Images
[Framework practical 7 of 7]


We'll now test our image method by displaying the image produced on our frame.


We now need to call the Storage object's getDataAsImage method from inside Analyst's paint method.

If you wrote the code for the last practical ok, store should now be an instance variable in Analyst, and therefore available in all the methods. We should, therefore, be able to alter the code in Analyst's paint method to:

   public void paint (Graphics g) {
      Image image = store.getDataAsImage(); // or equivalent
      g.drawImage(image, getInsets().left, getInsets().top, this);
   }

Test this code. You should initially see a black square in your frame. Try opening a file. If you don't see anything you may need to force the Analyst frame to repaint at the end of your actionPerformed method. Add the following line at the bottom of actionPerformed:

repaint();

If you've done that, you're done for this practical. Congratulations, you've finished your basic raster GIS framework; we'll be using this in the second assessment, which is going to add some more processing to it. You've now got an application that reads in files, stores the data, displays it as an image, and can write the data out.

If, however, you want to smarten your application up a bit, you'll find a few suggestions in Part 3.