1
0

Examples.st 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. Smalltalk current createPackage: 'Examples'!
  2. Widget subclass: #Counter
  3. instanceVariableNames: 'count header'
  4. package: 'Examples'!
  5. !Counter commentStamp!
  6. This is a trivial Widget example mimicking the classic Counter example in Seaside.
  7. In order to play with it, just evaluate the doit below in a workspace.
  8. Then take a look in the HTML document above the IDE.
  9. Counter new appendToJQuery: 'body' asJQuery!
  10. !Counter methodsFor: 'actions'!
  11. decrease
  12. count := count - 1.
  13. header contents: [:html | html with: count asString]
  14. !
  15. increase
  16. count := count + 1.
  17. header contents: [:html | html with: count asString]
  18. ! !
  19. !Counter methodsFor: 'initialization'!
  20. initialize
  21. super initialize.
  22. count := 0
  23. ! !
  24. !Counter methodsFor: 'rendering'!
  25. renderOn: html
  26. header := html h1
  27. with: count asString;
  28. yourself.
  29. html button
  30. with: '++';
  31. onClick: [self increase].
  32. html button
  33. with: '--';
  34. onClick: [self decrease]
  35. ! !
  36. !Counter class methodsFor: 'example'!
  37. tryExample
  38. "In order to play with the Counter, just select the
  39. doit below and press the Do it button. Then take a
  40. look in the HTML document above the IDE."
  41. "Counter tryExample"
  42. self new appendToJQuery: 'body' asJQuery
  43. ! !