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 >
Text File  |  2001-02-28  |  16KB  |  332 lines

  1. INTRODUCTION TO SQUEAK: A SCRIPT TO BE EXECUTED ON YOUR COMPUTER
  2. ================================================================
  3.  
  4. Your Name:  __________________________________________
  5.  
  6. Date Due:  January 15, 2001
  7.  
  8. Please write directly on this handout and turn it back in.  Go through the 
  9. script below.  As you do each thing, place a check-mark in the space to 
  10. indicate that you actually did it.  Fill-in answers where a blank line is 
  11. provided.
  12.  
  13.  
  14.  
  15. DOWNLOAD THE SQUEAK SYSTEM
  16. ==========================
  17.  
  18.   Download the SQUEAK Software and put it on your computer.  The software is 
  19.     available at either...
  20.       (1) www.squeak.org
  21.       (2) On the CD included with the Squeak textbook
  22.       (3) The OGI Sun System (try /usr/loca/apps/...)
  23.  
  24.   The necessary files are:
  25.     Squeak 2.8 VM      -- This is the Virtual machine, the application program.
  26.     Squeak2.8.image    -- This binary file contains the initial collection of
  27.                           objects
  28.     Squeak2.8.changes  -- This text file contain more source code
  29.     SqueakV2.sources   -- This text file contains distributed Smalltalk source
  30.                          code
  31.  
  32.   To start up the system, run the VM on the "image" file.  In the Macintosh, 
  33.     this is done by double clicking on the "image" file.  Later you will create 
  34.     your own "image" and  "changes" file, but you will always use the "VM" and 
  35.     the "sources" files.
  36.  
  37.   _  Download the SQUEAK System and get into it.
  38.  
  39. SYSTEM MENU AND MOUSE BUTTONS
  40. =============================
  41.  
  42.   _ While the cursor is in the background, click the mouse to bring up the 
  43.     "system menu."
  44.   _ Select "restore display" (to repaint the screen).
  45.  
  46.   Smalltalk was designed assuming a three-button mouse.  On the Mac and PC, you 
  47.     must press extra keys while mousing to achieve correct operation.  To 
  48.     prevent confusion, the mouse buttons are often referred to by colors in the 
  49.     Smalltalk software.
  50.  
  51. Symbolic    Macintosh      PC           3-buttons     Usage
  52. ========    =============  ===========  ============  =========================
  53. Red         Mouse          Left-Mouse   Left-Button   Selecting stuff, pointing
  54. Yellow      Option-Mouse   Right-Mouse  Middle-Button Appl.-specific menus
  55. Blue        Command-Mouse  Alt-Mouse    Right-Button  Window, system menus
  56.  
  57. TERMINATING AND RESTARTING A SESSION
  58. ====================================
  59.  
  60.   A Smalltalk session is normally terminated by writing out all of your objects 
  61.   to a disk file called a snapshot or image file.  When you first startup 
  62.   Smalltalk, the machine's RAM is loaded with an initial set of objects, which 
  63.   includes a vast amount of pre-existing code.  You will modify these objects 
  64.   during your Smalltalk session and then save them into your image file when you
  65.   are done.  When you terminate Smalltalk, you will "save" a snapshot of your 
  66.   memory and all your objects.  The next time you use Smalltalk, memory will be 
  67.   reloaded from this file and the state of the system will be exactly as you
  68.   left it.  The snapshot file will be named xxxxx.image, where xxxxx is 
  69.   something you will choose, like "MyWork.image".  There will be a corresponding
  70.   "changes" file, with a name such as "MyWork.changes"
  71.  
  72.   _ Make your first snapshot by selecting "save as..." from the system menu. 
  73.     Type a name for your image file, such as "MyWork.image".  (Saving may take a 
  74.     second or two.)  You may save an image any time you wish, by selecting the
  75.     "save" option from the system menu.  If the Smalltalk system crashes, and 
  76.     you restart it, the state will revert to the last snapshot you made.
  77.  
  78.     Another file called MyWork.changes was also be created.  For the most part 
  79.     it can be ignored, but if a crash occurs you could use it to recover changes 
  80.     made after the last snapshot.
  81.  
  82.   _ Select "quit" on the system menu to exit the Smalltalk environment.
  83.   _ Get back into Smalltalk.
  84.  
  85. COLLAPSE AND / OR CLOSE UNNEEDED WINDOWS
  86. ========================================
  87.  
  88.     Each window has a title bar with a "close" box in the upper LEFT and a 
  89.     "collapse" box in the upper RIGHT.
  90.  
  91.   _ In the initial image, you will see several windows on the screen.  Collapse 
  92.     the windows called "Getting Started..." and "Welcome To...".  Then 
  93.     "uncollapse" them back to their original size.
  94.  
  95. WORKSPACES
  96. ==========
  97.  
  98.  _ Open a workspace.
  99.      Select "open..." in the system menu; then select "workspace" from the 
  100.      sub-menu.
  101.  _ Practice resizing and moving windows.
  102.      Make the window taller, by grabbing it at the top of the title bar.
  103.      Make the window larger, by grabbing it at the lower right corner.
  104.      Move the window by grabbing the title bar and dragging it.
  105.      Close the window by pressing the "close" box in the upper left corner.
  106.      Note that a scroll bar appears when the cursor is in the workspace.  Ignore 
  107.        the scroll bar for now.
  108.  _ The Blue-button Menu
  109.      (The commands on this menu apply to a specific workspace and it is only 
  110.        available when the cursor is over the workspace.)
  111.      Select "edit label" to change the label in the title tab of the workspace. 
  112.        This brings up a prompter - this is the same prompter used when saving a 
  113.        snapshot.
  114.      Experiment with "move", "frame", "full screen", "collapse" and "close".
  115.      Select "choose color".  The system is now waiting for you to select a color
  116.      for the window.  Position the mouse anywhere on the screen and click it to 
  117.      select a color.
  118.  _ Window Selection
  119.      Windows are also called "views".  At any time only one view is active.  The 
  120.        active view has its label highlighted.
  121.      Create a second workspace and experiment with changing the active view with 
  122.        the red button.
  123.      Experiment with overlapping views.
  124.  _ Text Editing in a Workspace
  125.      Type a sentence or two into a workspace.
  126.      Use the return, tab and backspace keys.
  127.      Use the red button to select some characters.  (Press, drag, and release.)
  128.      Type characters to replace the highlighted characters.
  129.      Try inserting and deleting characters after repositioning the cursor.
  130.      Click the mouse button twice without moving it.  This is called double-
  131.        clicking.  What does it do when the cursor is in the middle of a word, at 
  132.        the beginning of a line, at the beginning of the workspace or after 
  133.        quotes or parentheses?  (This feature will come in handy in matching 
  134.        nested brackets [[][][[]]] and parentheses when you are writing code.)
  135.      Bring up the yellow button menu and practice using "copy", "cut" and 
  136.        "paste". (There is a "copy buffer" for text that has been cut.  "Copy" 
  137.         saves into this buffer without cutting.)
  138.      Practice using short-cut keys for copy, cut, and paste.  On the Macintosh, 
  139.        hold down the command key and type "c".  On the PC, hold down ALT and 
  140.        type "c".
  141.             Mac    PC     Menu Action
  142.             =====  =====  ===========
  143.             cmd-x  alt-x  cut
  144.             cmd-c  alt-c  copy
  145.             cmd-v  alt-v  paste
  146.  _ Scrolling
  147.      Using "copy" and "paste", type in more than will fit in the view.
  148.      Move the cursor over scroll bar.  (When centered, it will be a right-
  149.        pointing arrow.  Otherwise, a "half-arrow" will appear pointing either up 
  150.        or down.)  
  151.      Press the left button and drag the right-pointing arrow.
  152.      Figure out how the up- and down-pointing half-arrows work.
  153.      Notice that when the cursor is near the scroll bar, it changes into a tiny 
  154.        menu icon.  Press the red mouse button here to get a menu.  This is a 
  155.        nice short-cut, especially on the Macintosh.
  156.  _ Message Sending
  157.      Type "2+3", select it and then select the "print it" menu option.
  158.      ("Print it" and "do it" only work on the selected text.  Both commands
  159.        evaluate the selected expression.  The "print it" command displays the 
  160.        result, but the "do it" option doesn't display the returned value.)
  161.      The short-cut key for "print it" is (Macintosh: cmd-p) and (PC: alt-p).
  162.      The short-cut key for "do it" is (Macintosh: cmd-d) and (PC: alt-d).  These 
  163.        are very common actions, so practice the short-cut keys.
  164.  _ Undo, Searching
  165.      Experiment with "undo", to un-do the last change.
  166.      Experiment with searching the workspace for a string.
  167.      Use the shortcut keys as well as the menu items.
  168.             Mac    PC     Menu Action
  169.             =====  =====  ===========
  170.             cmd-f  alt-f  find...
  171.             cmd-g  alt-g  find again
  172.             cmd-h  alt-h  set search string
  173.             cmd-z  alt-z  un do
  174.  _ Confirmers and Accept, Cancel
  175.      Figure out how the "accept" and "cancel" commands work.  (Workspaces keep a 
  176.        back-up copy.  "Accept" writes into this copy.  Make some changes.  
  177.        "Cancel" takes the workspace back to the last copy saved by "accept".)
  178.      Do an "accept" and then close the workspace.
  179.      In another workspace, make some changes without accepting them and try 
  180.        closing this workspace.  (A confirmer should appear; Try ignoring the 
  181.        question-what happens?)
  182.  
  183. GRAPHICS DEMO PROGRAMS
  184. ======================
  185.  
  186.   _  In a workspace, type "Spline example", select it and "do it".
  187.        (Use the red button to click off several points on the screen.  Then 
  188.        click another button - you should see a curve.  Does the curve have to 
  189.        lie inside a view?)
  190.      What does "restore display" do to the curve?
  191.      What do scroll bars do to the curve?  Why?
  192.   _  Type in "Spline example1", then select "do it".  This is a typo and you 
  193.        should see a window pop up.  Push the "Abandon" button.  ("example1" is a 
  194.        valid message, just not for Splines.)
  195.   _  Type in "Spline exampl" then "do it".  This is also a typo, but this time 
  196.      Smalltalk suggests some possible corrections.  Select "cancel" or 
  197.        "example".  (Here "exampl" is not even a valid message so the system 
  198.        looks for messages with similar spellings.)
  199.   _  Execute "Line example", then select two points.  (By execute it, we mean
  200.        select it and "do it".)
  201.   _  Execute "LinearFit example".  It functions much like Spline.
  202.   _  Execute "Circle exampleOne" and then select a point.
  203.   _  Execute "CurveFitter example" and the select 3 points.
  204.   _  Execute "Circle exampleTwo".  First select a fairly small rectangle (1/2" 
  205.        by 1/2") that contains some black pixels.  Then select a point.
  206.  
  207. THE FILE LIST PROGRAM
  208. =====================
  209.  
  210.   _ From the system menu, select "open...file list".
  211.       You should see a view with several "sub-views" (or "panes").  This should 
  212.       give you a view of the current directory.  In the upper-right subview, 
  213.       you'll see all the files in the directory.  In the upper-left window pane 
  214.       you'll see the super-directories, so you know where you are.  Select a 
  215.       file in the upper-right subview.  (Choose a small text file.)  You should 
  216.       see its contents in the bottom subview.
  217.   _ The bottom subview is similar to a workspace.  You may edit files this way.  
  218.       Actually, you are editing an in-memory copy.  Use "accept" (or cmd-s /
  219.       alt-s) to write the in-memory copy back to disk.  Use "cancel" to revert 
  220.       to the old version without updating.
  221. File Creation and Removal
  222.  _ In the upper-right subview, select "add new file" and give it a name.  This 
  223.      creates a zero-length file.
  224.  _ Make some changes to a file, write them out, and read the changes back in.
  225.  _ Use "delete" to remove this and other unneeded files.
  226.      Select the "more..." menu option and take a look at the submenu options.  
  227.      "file In" is used for reading and compiling Smalltalk source code.
  228.  
  229. FORMS
  230. =====
  231.  
  232. Forms are rectangular blocks of pixels, like mini-bitmaps.
  233.  
  234.  _ In a workspace, execute "f := Form fromUser".  Then select a rectangle from 
  235.      the screen.
  236.      (There are two ways to type the assignment operator.  You may either type
  237.        colon-equal (like Pascal) or you may use the left arrow, which is really 
  238.        the ASCII underscore (_) character.  In other words, type the _ key and
  239.        see <- on the display.
  240.      Select a rectangle on the screen.  (This expression created a new form and 
  241.        assigns it to variable f.)
  242.  _ Execute "f <- Form fromUser" (Same statement, just use the left-arrow this 
  243.      time. "<-" means left arrow in this document.)
  244.  _ Execute "f displayAt: 100 @ 100".  Use "restore display" if necessary.
  245.  _ Use cmd-h / alt-h (which is the "set search string" menu option) to select 
  246.      the entire line.  Then use cmd-d / alt-d (which is the "do it" menu option) 
  247.      to execute these statements.
  248.  _ Experiment with different display locations and variable names by re-sending 
  249.      these messages.  (Points, such as 100@100, are specified by expressions 
  250.      that use the @ character as a binary infix operator.  For example 20@500 
  251.      means the point (x=20, y=500).  The upper-left corner of the screen is 
  252.      position 0@0.  The y coordinate runs down the screen.)
  253.  _ Use "f <- Form extent: 30@40" to create a blank form.  The extent means that 
  254.      this form is 30 pixels wide (x) and 40 pixels high (y).
  255.  _ Execute "f displayAt: Sensor waitButton".
  256.  
  257. THE BIT EDITOR
  258. ==============
  259.  
  260.  _ Execute "f <- Form extent: 16 @ 16".
  261.  _ Execute "f bitEdit" and bring up a new view.
  262.  _ Experiment with modifying this new form.  There is a button at the bottom of 
  263.      the BitEditor view.  Click it, then click on a black or white pixel 
  264.      anywhere on the screen.  Now you can draw with the selected color.
  265.    Select "accept", then go back to workspace, without closing the bit editor.
  266.  _ Execute "f displayAt: 100 @ 100".  What happened?
  267.      Does the bit editor ask for confirmation before closing when you haven't 
  268.      first "accept"ed your changes?
  269.  _ Try editing a color form.  Paint colored pixels into the form and display it 
  270.      with:
  271.         g <- Form extent: 30@30 depth: Display depth.  "Create a form with
  272.                                                         colored pixels."
  273.         BitEditor openOnForm: g.
  274.         g displayAt: Sensor waitButton.
  275.  _ Experiment with various mouse messages:
  276.         g displayAt: Sensor waitButton.
  277.         g displayAt: Sensor waitClickButton.
  278.         g displayAt: Sensor waitNoButton.
  279.         g displayAt: Sensor mousePoint.
  280.  
  281. CREATE A 25 X 25 FORM
  282. =====================
  283.  
  284.  _ Type and execute with the following 5 lines:
  285.        circleForm <- Form extent: 25 @ 25.
  286.        aCircle <- Circle new.
  287.        aCircle radius: 12.
  288.        aCircle center: 12 @ 12.
  289.        aCircle displayOn: circleForm.
  290.  _ Describe what you think this code does.  (Hint: you won't see any effects 
  291.        directly.)
  292.  
  293.  
  294. ______________________________________________________________________________
  295.      Type in and evaluate some expressions to verify this code does what you
  296.      say it does.
  297.  
  298. USING A SYSTEM BROWSER
  299. ======================
  300.  
  301.  _ Open a "system browser" from the system menu.  (The upper 4 panes in the 
  302.        browser contain lists.  Practice scrolling and selecting items from the 
  303.        lists.  Note how selections in one list affect the lists to its right.)
  304.  _ Look at some methods in the lower pane.
  305.  _ Examine the menus in each pane of the browser.  See if you can figure out 
  306.        what some of the menu options do.  (Selecting accept in the lower pane 
  307.        will re-compile the method if you made any changes.  Select cancel if 
  308.        wish to avoid a compile and revert to the previous text.)
  309.  _ Locate the even method in class Integer.  How does this method determine 
  310.        its result?
  311.  
  312.  
  313. ______________________________________________________________________________
  314.  
  315. COMMENTS
  316. ========
  317.  
  318. Do you have any comments about this script?  For future reference, were any 
  319. instructions unclear/frustrating (which ones)?
  320.  
  321.  
  322. ______________________________________________________________________________
  323.  
  324.  
  325. ______________________________________________________________________________
  326.  
  327.  
  328. ______________________________________________________________________________
  329.  
  330.  
  331.  
  332.