StringMorph and SimpleButtonMorph example -- another counter
Last updated at 8:41 pm UTC on 21 August 2019
Source: http://forum.world.st/Just-playin-around-tp5102323p5102327.html
Paste the following code snippet into a Workspace and execute the code.
Since all variables {s,bp,bm} are workspace shared you can also run the lines one at a time and see what happens into the Workspace.
s := StringMorph new.
s openInWorld .
s contents: '0'.
s position: 100@100.
bp := SimpleButtonMorph new.
bp openInWorld .
bp label: 'Plus-1'.
bp position: 150@100.
bm := SimpleButtonMorph new.
bm openInWorld .
bm label: 'Minus-1'.
bm position: 250@100.
"------ Add actions to buttons ------------ "
bp target: [ s contents: (s contents asInteger + 1) asString ].
bp actionSelector: #value.
bm target: [ s contents: (s contents asInteger - 1) asString ].
bm actionSelector: #value.

tagBeginner