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
- Create a new MorphicProject
- add three morphs s,bm and bp to that new project (StringMorph and two button morphs)
- hide the docking bar in the new project
- set the background color of the new project to yellow
- open the project view morph in the current project thus giving access to the newly created MorphicProject
| 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.