Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
How to create a new project with code - example 3
Last updated at 10:59 am UTC on 25 July 2022

Example 3

The example is similar to example 1 and is based on StringMorph and SimpleButtonMorph example -- another counter

 | newProject  |
 newProject := MorphicProject  new.
 newProject name: 'MyCounter'.

 s := StringMorph new.
 newProject world addMorph: s.
 s contents: '0'.
 s position: 100@100.

 bp := SimpleButtonMorph new.
 newProject world addMorph: bp.
 bp label: 'Plus-1'.
 bp position: 150@100.

 bm := SimpleButtonMorph new.
 newProject world addMorph: bm.
 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. 


 newProject showWorldMainDockingBar: false.
 newProject world color: Color yellow twiceLighter.
 ProjectViewMorph openOn: newProject.