2
0

Examples.st 687 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. Smalltalk current createPackage: 'Examples' properties: #{}!
  2. Widget subclass: #Counter
  3. instanceVariableNames: 'count header'
  4. category: 'Examples'!
  5. !Counter methodsFor: 'actions'!
  6. increase
  7. count := count + 1.
  8. header contents: [:html | html with: count asString]
  9. !
  10. decrease
  11. count := count - 1.
  12. header contents: [:html | html with: count asString]
  13. ! !
  14. !Counter methodsFor: 'initialization'!
  15. initialize
  16. super initialize.
  17. count := 0
  18. ! !
  19. !Counter methodsFor: 'rendering'!
  20. renderOn: html
  21. header := html h1
  22. with: count asString;
  23. yourself.
  24. html button
  25. with: '++';
  26. onClick: [self increase].
  27. html button
  28. with: '--';
  29. onClick: [self decrease]
  30. ! !