home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ee.pdx.edu
/
2014.02.ftp.ee.pdx.edu.tar
/
ftp.ee.pdx.edu
/
pub
/
users
/
Harry
/
cse509
/
oop-script
< prev
next >
Wrap
Text File
|
2001-02-28
|
16KB
|
332 lines
INTRODUCTION TO SQUEAK: A SCRIPT TO BE EXECUTED ON YOUR COMPUTER
================================================================
Your Name: __________________________________________
Date Due: January 15, 2001
Please write directly on this handout and turn it back in. Go through the
script below. As you do each thing, place a check-mark in the space to
indicate that you actually did it. Fill-in answers where a blank line is
provided.
DOWNLOAD THE SQUEAK SYSTEM
==========================
Download the SQUEAK Software and put it on your computer. The software is
available at either...
(1) www.squeak.org
(2) On the CD included with the Squeak textbook
(3) The OGI Sun System (try /usr/loca/apps/...)
The necessary files are:
Squeak 2.8 VM -- This is the Virtual machine, the application program.
Squeak2.8.image -- This binary file contains the initial collection of
objects
Squeak2.8.changes -- This text file contain more source code
SqueakV2.sources -- This text file contains distributed Smalltalk source
code
To start up the system, run the VM on the "image" file. In the Macintosh,
this is done by double clicking on the "image" file. Later you will create
your own "image" and "changes" file, but you will always use the "VM" and
the "sources" files.
_ Download the SQUEAK System and get into it.
SYSTEM MENU AND MOUSE BUTTONS
=============================
_ While the cursor is in the background, click the mouse to bring up the
"system menu."
_ Select "restore display" (to repaint the screen).
Smalltalk was designed assuming a three-button mouse. On the Mac and PC, you
must press extra keys while mousing to achieve correct operation. To
prevent confusion, the mouse buttons are often referred to by colors in the
Smalltalk software.
Symbolic Macintosh PC 3-buttons Usage
======== ============= =========== ============ =========================
Red Mouse Left-Mouse Left-Button Selecting stuff, pointing
Yellow Option-Mouse Right-Mouse Middle-Button Appl.-specific menus
Blue Command-Mouse Alt-Mouse Right-Button Window, system menus
TERMINATING AND RESTARTING A SESSION
====================================
A Smalltalk session is normally terminated by writing out all of your objects
to a disk file called a snapshot or image file. When you first startup
Smalltalk, the machine's RAM is loaded with an initial set of objects, which
includes a vast amount of pre-existing code. You will modify these objects
during your Smalltalk session and then save them into your image file when you
are done. When you terminate Smalltalk, you will "save" a snapshot of your
memory and all your objects. The next time you use Smalltalk, memory will be
reloaded from this file and the state of the system will be exactly as you
left it. The snapshot file will be named xxxxx.image, where xxxxx is
something you will choose, like "MyWork.image". There will be a corresponding
"changes" file, with a name such as "MyWork.changes"
_ Make your first snapshot by selecting "save as..." from the system menu.
Type a name for your image file, such as "MyWork.image". (Saving may take a
second or two.) You may save an image any time you wish, by selecting the
"save" option from the system menu. If the Smalltalk system crashes, and
you restart it, the state will revert to the last snapshot you made.
Another file called MyWork.changes was also be created. For the most part
it can be ignored, but if a crash occurs you could use it to recover changes
made after the last snapshot.
_ Select "quit" on the system menu to exit the Smalltalk environment.
_ Get back into Smalltalk.
COLLAPSE AND / OR CLOSE UNNEEDED WINDOWS
========================================
Each window has a title bar with a "close" box in the upper LEFT and a
"collapse" box in the upper RIGHT.
_ In the initial image, you will see several windows on the screen. Collapse
the windows called "Getting Started..." and "Welcome To...". Then
"uncollapse" them back to their original size.
WORKSPACES
==========
_ Open a workspace.
Select "open..." in the system menu; then select "workspace" from the
sub-menu.
_ Practice resizing and moving windows.
Make the window taller, by grabbing it at the top of the title bar.
Make the window larger, by grabbing it at the lower right corner.
Move the window by grabbing the title bar and dragging it.
Close the window by pressing the "close" box in the upper left corner.
Note that a scroll bar appears when the cursor is in the workspace. Ignore
the scroll bar for now.
_ The Blue-button Menu
(The commands on this menu apply to a specific workspace and it is only
available when the cursor is over the workspace.)
Select "edit label" to change the label in the title tab of the workspace.
This brings up a prompter - this is the same prompter used when saving a
snapshot.
Experiment with "move", "frame", "full screen", "collapse" and "close".
Select "choose color". The system is now waiting for you to select a color
for the window. Position the mouse anywhere on the screen and click it to
select a color.
_ Window Selection
Windows are also called "views". At any time only one view is active. The
active view has its label highlighted.
Create a second workspace and experiment with changing the active view with
the red button.
Experiment with overlapping views.
_ Text Editing in a Workspace
Type a sentence or two into a workspace.
Use the return, tab and backspace keys.
Use the red button to select some characters. (Press, drag, and release.)
Type characters to replace the highlighted characters.
Try inserting and deleting characters after repositioning the cursor.
Click the mouse button twice without moving it. This is called double-
clicking. What does it do when the cursor is in the middle of a word, at
the beginning of a line, at the beginning of the workspace or after
quotes or parentheses? (This feature will come in handy in matching
nested brackets [[][][[]]] and parentheses when you are writing code.)
Bring up the yellow button menu and practice using "copy", "cut" and
"paste". (There is a "copy buffer" for text that has been cut. "Copy"
saves into this buffer without cutting.)
Practice using short-cut keys for copy, cut, and paste. On the Macintosh,
hold down the command key and type "c". On the PC, hold down ALT and
type "c".
Mac PC Menu Action
===== ===== ===========
cmd-x alt-x cut
cmd-c alt-c copy
cmd-v alt-v paste
_ Scrolling
Using "copy" and "paste", type in more than will fit in the view.
Move the cursor over scroll bar. (When centered, it will be a right-
pointing arrow. Otherwise, a "half-arrow" will appear pointing either up
or down.)
Press the left button and drag the right-pointing arrow.
Figure out how the up- and down-pointing half-arrows work.
Notice that when the cursor is near the scroll bar, it changes into a tiny
menu icon. Press the red mouse button here to get a menu. This is a
nice short-cut, especially on the Macintosh.
_ Message Sending
Type "2+3", select it and then select the "print it" menu option.
("Print it" and "do it" only work on the selected text. Both commands
evaluate the selected expression. The "print it" command displays the
result, but the "do it" option doesn't display the returned value.)
The short-cut key for "print it" is (Macintosh: cmd-p) and (PC: alt-p).
The short-cut key for "do it" is (Macintosh: cmd-d) and (PC: alt-d). These
are very common actions, so practice the short-cut keys.
_ Undo, Searching
Experiment with "undo", to un-do the last change.
Experiment with searching the workspace for a string.
Use the shortcut keys as well as the menu items.
Mac PC Menu Action
===== ===== ===========
cmd-f alt-f find...
cmd-g alt-g find again
cmd-h alt-h set search string
cmd-z alt-z un do
_ Confirmers and Accept, Cancel
Figure out how the "accept" and "cancel" commands work. (Workspaces keep a
back-up copy. "Accept" writes into this copy. Make some changes.
"Cancel" takes the workspace back to the last copy saved by "accept".)
Do an "accept" and then close the workspace.
In another workspace, make some changes without accepting them and try
closing this workspace. (A confirmer should appear; Try ignoring the
question-what happens?)
GRAPHICS DEMO PROGRAMS
======================
_ In a workspace, type "Spline example", select it and "do it".
(Use the red button to click off several points on the screen. Then
click another button - you should see a curve. Does the curve have to
lie inside a view?)
What does "restore display" do to the curve?
What do scroll bars do to the curve? Why?
_ Type in "Spline example1", then select "do it". This is a typo and you
should see a window pop up. Push the "Abandon" button. ("example1" is a
valid message, just not for Splines.)
_ Type in "Spline exampl" then "do it". This is also a typo, but this time
Smalltalk suggests some possible corrections. Select "cancel" or
"example". (Here "exampl" is not even a valid message so the system
looks for messages with similar spellings.)
_ Execute "Line example", then select two points. (By execute it, we mean
select it and "do it".)
_ Execute "LinearFit example". It functions much like Spline.
_ Execute "Circle exampleOne" and then select a point.
_ Execute "CurveFitter example" and the select 3 points.
_ Execute "Circle exampleTwo". First select a fairly small rectangle (1/2"
by 1/2") that contains some black pixels. Then select a point.
THE FILE LIST PROGRAM
=====================
_ From the system menu, select "open...file list".
You should see a view with several "sub-views" (or "panes"). This should
give you a view of the current directory. In the upper-right subview,
you'll see all the files in the directory. In the upper-left window pane
you'll see the super-directories, so you know where you are. Select a
file in the upper-right subview. (Choose a small text file.) You should
see its contents in the bottom subview.
_ The bottom subview is similar to a workspace. You may edit files this way.
Actually, you are editing an in-memory copy. Use "accept" (or cmd-s /
alt-s) to write the in-memory copy back to disk. Use "cancel" to revert
to the old version without updating.
File Creation and Removal
_ In the upper-right subview, select "add new file" and give it a name. This
creates a zero-length file.
_ Make some changes to a file, write them out, and read the changes back in.
_ Use "delete" to remove this and other unneeded files.
Select the "more..." menu option and take a look at the submenu options.
"file In" is used for reading and compiling Smalltalk source code.
FORMS
=====
Forms are rectangular blocks of pixels, like mini-bitmaps.
_ In a workspace, execute "f := Form fromUser". Then select a rectangle from
the screen.
(There are two ways to type the assignment operator. You may either type
colon-equal (like Pascal) or you may use the left arrow, which is really
the ASCII underscore (_) character. In other words, type the _ key and
see <- on the display.
Select a rectangle on the screen. (This expression created a new form and
assigns it to variable f.)
_ Execute "f <- Form fromUser" (Same statement, just use the left-arrow this
time. "<-" means left arrow in this document.)
_ Execute "f displayAt: 100 @ 100". Use "restore display" if necessary.
_ Use cmd-h / alt-h (which is the "set search string" menu option) to select
the entire line. Then use cmd-d / alt-d (which is the "do it" menu option)
to execute these statements.
_ Experiment with different display locations and variable names by re-sending
these messages. (Points, such as 100@100, are specified by expressions
that use the @ character as a binary infix operator. For example 20@500
means the point (x=20, y=500). The upper-left corner of the screen is
position 0@0. The y coordinate runs down the screen.)
_ Use "f <- Form extent: 30@40" to create a blank form. The extent means that
this form is 30 pixels wide (x) and 40 pixels high (y).
_ Execute "f displayAt: Sensor waitButton".
THE BIT EDITOR
==============
_ Execute "f <- Form extent: 16 @ 16".
_ Execute "f bitEdit" and bring up a new view.
_ Experiment with modifying this new form. There is a button at the bottom of
the BitEditor view. Click it, then click on a black or white pixel
anywhere on the screen. Now you can draw with the selected color.
Select "accept", then go back to workspace, without closing the bit editor.
_ Execute "f displayAt: 100 @ 100". What happened?
Does the bit editor ask for confirmation before closing when you haven't
first "accept"ed your changes?
_ Try editing a color form. Paint colored pixels into the form and display it
with:
g <- Form extent: 30@30 depth: Display depth. "Create a form with
colored pixels."
BitEditor openOnForm: g.
g displayAt: Sensor waitButton.
_ Experiment with various mouse messages:
g displayAt: Sensor waitButton.
g displayAt: Sensor waitClickButton.
g displayAt: Sensor waitNoButton.
g displayAt: Sensor mousePoint.
CREATE A 25 X 25 FORM
=====================
_ Type and execute with the following 5 lines:
circleForm <- Form extent: 25 @ 25.
aCircle <- Circle new.
aCircle radius: 12.
aCircle center: 12 @ 12.
aCircle displayOn: circleForm.
_ Describe what you think this code does. (Hint: you won't see any effects
directly.)
______________________________________________________________________________
Type in and evaluate some expressions to verify this code does what you
say it does.
USING A SYSTEM BROWSER
======================
_ Open a "system browser" from the system menu. (The upper 4 panes in the
browser contain lists. Practice scrolling and selecting items from the
lists. Note how selections in one list affect the lists to its right.)
_ Look at some methods in the lower pane.
_ Examine the menus in each pane of the browser. See if you can figure out
what some of the menu options do. (Selecting accept in the lower pane
will re-compile the method if you made any changes. Select cancel if
wish to avoid a compile and revert to the previous text.)
_ Locate the even method in class Integer. How does this method determine
its result?
______________________________________________________________________________
COMMENTS
========
Do you have any comments about this script? For future reference, were any
instructions unclear/frustrating (which ones)?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________