Useful Methods

This document contains useful methods for accomplishing a variety of tasks in ABC. You can use them as templates, making changes to meet your needs. If you have ABC running along with this document, you can copy and paste the code into a method editor to avoid typing the code.

If you have a method to include or have a suggestion for a method you would like to see, send a note to Pete Boysen. The current topics include:


Showing Pages

Show two pages, Page1 in the main window and Help1 in a help window:


click theManager:Manualman with anEvent:Event
  { theManager showPage "Page1".
    theManager showPage "Help1" in "Help" at #right.
  }


Drawing Graphics

Display the text "Good job." at 300,400.


click theManager:Manualman with anEvent:Event
  { txt -> Text newText ["Good job."].
    txt movex 300 movey 400.
    txt drawIn theWindow.
  }

Make the text red. To determine the color number, select Options/Font... from the Page Manager.


click theManager:Manualman with anEvent:Event
  { txt -> Text newText ["Good job."].
    txt foreground 2.
    txt movex 300 movey 400.
    txt drawIn theWindow.
  }

Set the font to bold helvetica, point size 18. The typefaces are courier, times and helvitica; the styles are #normal, #bold, #italics and #bolditalics; the point sizes are 10, 12, 14, 18 and 24.


click theManager:Manualman with anEvent:Event
  { txt -> Text newText ["Good job."].
    txt setFontTo (Font typeface "helvetica" style #bold pointSize 18).
    txt movex 300 movey 400.
    txt drawIn theWindow.
  }

Draw a horizontal line.


click theManager:Manualman with anEvent:Event
  { aLine -> (Line new) from (100@50) to (200@50).
    aLine drawIn theWindow.
  }

Make it dotted and 2 lines wide. Other styles are #solid, #dash or #dotdash.


click theManager:Manualman with anEvent:Event
  { aLine -> (Line new) from (100@50) to (200@50).
    aLine lineStyle #dot.
    aLine lineWidth 2.
    aLine drawIn theWindow.
  }

Make a filled triangle. The number of the fill pattern can be found by selecting Options/Fill... from the Page Manager. Polygon styles can be #openline, #closedline, #opencurve or #closedcurve.


click theManager:Manualman with anEvent:Event
  { aTriangle -> Polygon origin (200@200) points [0@100,50@0,100@100].
    aTriangle polyStyle #closedline.
    aTriangle fillStyle 4.
    aTriangle drawIn theWindow.
  }

Detect if the user clicked in a small box named "smbox" which is contained in a larger box named "bigbox". The method associated with the big box will print a message saying that the small box was missed.


click theManager:Manualman with anEvent:Event
  { rec1 -> Rectangle new.
    (me getFigure "smbox") extentIn rec1.
    pt -> Point x anEvent's x y anEvent's y.
    (rec1 contains pt) then 
    { me eraseFrom (75 @ 1100) to (1100 @ 1300).
      msg -> Text newText ["Good job!"].
      msg setFontTo (Font typeface "times" style #bold pointSize 24).
      me draw msg at (75 @ 1100).
    }.
  }


Quizzing

The following method will show a total score on page "summary" if the score is less than 50. You should place a button on this page which will show missed questions (see below). If the student already viewed the quiz they will be taken back to "Main Menu". If all the answers were correct, the student will be shown page "All Correct". Modify the page names and minimum score to mee your needs.


doneFor theManager:Manualman
  { theQuiz's review then
    { theManager showPage "Main Menu".
    } else
    { n -> theQuiz totalScore.
      (n < 50) then
      { txt -> Text newText [n asString "Your total score was %d"].
        txt movex 200 movey 250.
        txt setFontTo (Font typeface "helvetica" style #normal
               pointSize 18).
        theManager showPage "Summary".
        txt drawIn theWindow.
      } else
      { theManager showPage "All Correct".
      }.
    }.
  }

Once a quiz has been given, you can display the missed questions (i.e. scores less than 1) by using the following method:


click theManager:Manualman with anEvent:Event
  { n -> theQuiz reviewScoresLessThan 1.
    (n > 0) then
    { theQuiz startQuizFor theManager.
    } else
    { !! just go on if none were missed
      theManager showPage "Main Menu".
    }.
  }