View this PageEdit this Page (locked)Attachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Lab1 - Sp2000


Lab 1: A Squeak Treasure Hunt


The Why

In this lab you'll learn more about the Squeak Smalltalk programming system. You'll become great friends with the System Browser and hopefully become a little more comfortable working with both Squeak and Smalltalk. The difficult thing about learning Squeak is that the progamming environment seems so "huge" - there's so much stuff to learn about and learn how to use. What you'll come to realize is this difficult thing is actually Squeak's biggest asset - there's so much stuff to learn about and learn how to use! In very rough terms, more stuff = more power = more things you can do with Squeak, once you learn your way around. This lab should get you off to a good start.

The What

Armed with your new knowledge, you're going to embark on a great quest: finding some gems in Squeak.

Here's the scenario: you've been asked to prepare to write a class called ImageCollection. To do this, you'll want to explore Squeak for the different tools you might be able to use to implement the services ImageCollection is supposed to provide. You won't be writing any new code during this lab. For each section below, you'll be finding a relevant method in Squeak that either you could use directly to provide the service or you could modify to provide the service. When you find these methods, you'll copy and paste them into a Workspace window. At the end of the lab, you'll copy and turn in the entire contents of your Workspace.

Part 0

Open a new Workspace window for you to paste the code you find into. Left-click on the Squeak desktop and choose open...Workspace. You may want to click on the titlebar and rename this new Workspace so that you can tell it apart from your original one.

Part 1

ImageCollection loads a collection of images and will display one on command. The first method you would have to write is loadImages. loadImages will need to get some input from the user; for example, the user would need to tell ImageCollection how many images it should read. To do this, a window is displayed with an appropriate label (i.e. "How many images will be read?").

For this part, you need to locate a method that pops up a dialog box to ask the user a question and read a response. This happens in several places in Squeak, so it should be pretty easy to find. When you find this method being called somewhere, copy the entire method you found it in and paste it into your Workspace.

Hint: This pop-up window is similar to the window you'll see when you select "add new file" from the File List browser. The File List browser an instance of class FileList. There are several other places you can find this type of window - go hunting!

Part 2

Once loadImages has the information it needs, it should actually load the images. Since images can be large and the entire reading operation might take a while, ImageBlaster should display a progress bar while it loads the images. The progress bar should increment by 1 for each image that ImageBlaster reads.

For this part, you need to locate a method that will provide a progress bar while some operation is being performed. You may think there won't be any single method to do this, but recall that you've seen these progress bars in several places (when you fileIn code, for example) - Squeak comes with more ready-to-use tools (toys?) than you think! When you find this method, copy the calling method and add it to your Workspace.

Hint: In general, when you're looking for something to accomplish a particular task in Squeak, a good idea is to start with where you've seen that task being accomplished before. Remember that Squeak is written in itself, and OOP stresses code reuse!

Part 3

In order to display an image, Squeak has to retrieve the image from the file system and store it internally somehow. This means that Squeak must have some way to read in an image, given a filename, and return some object that is an internal representation of that image.

For this part, you need to locate a method to which you can provide a filename and which gives you back a suitable object. When you find this method, copy its selector to your Workspace (note this is different from the previous two parts - here you're trying just to find the method to use, rather than find an example of its use somewhere in Squeak).

Hint: Well, you're dealing with images, and you need to find a method that will read them. That ought to be enough information...

Part 4

Assuming that the images are stored somewhere in ImageCollector, the user will ask to display an image using the displayImage:withTitle: method. This method needs to display the image in a window with a titlebar, given the object that represents the image (you'll figure out what this object is when you solve Part 3). Squeak has made so many things easy for us so far - maybe you can get this accomplished too without too much trouble.

For this part, you need to locate a method to which you can provide:

and which will display the image in a window with an appropriate title. When you find this method, copy its selector to your Workspace.

Hint: Actions like the one you would need to perform in displayImage:withTitle: are frequently found in class methods. Look for example categories.

General Hints:

It will take some hunting to find the answers, and some may take several minutes if you are unlucky. Most widgets are started up by class methods, such make sure you look at both instance and class methods. Some classes override methods found in superclasses. Make sure you look at a classes' superclass; read the FAQ for easy ways to do this.

What to turn in

Copy all the text in your Workspace (what you found from Parts 1-4). And we will tell you what to do with it to actually turn it in.


Link to this Page