home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / Tutorial / Cookbook / 03a.events / notes < prev    next >
Encoding:
Text File  |  1993-01-18  |  2.2 KB  |  53 lines

  1. Objective:
  2.    Understand events and how they direct different sections of your
  3.       program to run.
  4.    Understand how to add state variables to your objects.
  5.    
  6. Terms:
  7.     Event: a user initiated action such as a mouse being clicked on a
  8.     button which causes a message to be sent to the appropriate object.
  9.     
  10.     Action message:  a message that notifies an object that an event
  11.     has occured.
  12.    
  13. Discussion:
  14.     In traditional programming, programmers think of a program
  15.     in which the program counter starts at the top of a pogram,
  16.     (typically called the "main" section) and continues in a
  17.     linear manner through the end of the program.  In event based
  18.     programming we think of a two dimensional array of "events" which
  19.     send "action messages" to various sections of code which respond to
  20.     these "events".  The order of when each section of code is executed
  21.     is not dependant on the order it appears in the file but on the order
  22.     that these events occur.
  23.     
  24. Method:
  25.    Create a new application with Interface Builder.
  26.    Drag two buttons on to the screen and label them "event 1"
  27.       and "event 2".
  28.    Create a new subclass of Object using the class editor.  Add two
  29.       actions "myEvent1:" and myEvent2:".
  30.    Create an instance of that Object using the "Objects/New Custom Object"
  31.       main menu selection.
  32.    Connect the buttons to the events of the object by CONTROL/CLICKing
  33.       from the buttons to the MyObject1 icon in the window created by
  34.       the "Windows/Objects..." panel.  Connect it to the icon titled
  35.       "MyObject1".  Connect the "event 1" button to the myEvent1 action
  36.       and the "event 2" button to the "myEvent 2" button by using the
  37.       inspector panel.
  38.  
  39. Futher Suggestions:
  40.    How would you go about initializing an internal state variable.
  41.    Why wouldn't you put initialization code in a method done by an
  42.    event?
  43.    Answer: you would use a "new" or "newFrame" method.  See module
  44.    "initialization".
  45.    
  46. Summary:
  47.    You now have the ability to have any "buttons" control execution of
  48.    any part of your objects code.  The internal state variables of any
  49.    objects you create can be changed directly by these actions.
  50.    
  51.    
  52.    
  53.