Home Segments Index Top Previous Next

804: Mainline

Change in a model is typically initiated by a button click or key press observed by a controller. The following illustrates such a button click or key press by employing a method that simulates a button click, rather than a real button click. Each time that a click is simulated, the x instance variable in the model is incremented by way of the setter, setX, which initiates the changed:update: sequence that leads to display by the viewer:

ControllerSubclass method definition • instance 
simulateClick 
  Transcript show: 'Button click simulated'; cr. 
  self model setX: (self model getX + 1). 
Workspace
C := ControllerSubclass new. 
C model: M. 
C simulateClick. 
C simulateClick. 
C simulateClick. 
Transcript 
Button click simulated 
Sample viewer responding to #x update message 
Model x value, determined in viewer, is 1 
Button click simulated 
Sample viewer responding to #x update message 
Model x value, determined in viewer, is 2 
Button click simulated 
Sample viewer responding to #x update message 
Model x value, determined in viewer, is 3 

In the click simulation, and the resulting action, you see activity analogous to that shown graphically in Segment 791.