=== Top of the Swiki === Attachments ===

OneWindowOneButton

Mail List Question:

How do you create a simple MVC application window containing a button? I could not find a Window class in Squeak and the View class's information is quite cryptic to the uninitiated.

The simplest one window and one button that I know:

 | topView aButton |
topView := StandardSystemView new
label: 'Launch Pad'.
aButton := Button newOff onAction: [Smalltalk beep].
"dummy launching action"

topView addSubView: (PluggableButtonView new
label: 'Beep' asParagraph;
insideColor: Color gray;
model: aButton; borderWidth: 1)
viewport: (0@0 corner: 1@1).
topView controller open.

- MarkGuzdial

SwitchView is an obsolete class. Use "PluggableButtonView" instead.

I went ahead and changed the source above because I made the mistake of cutting and pasting as soon as I saw the example, rather than reading the full text! ;-) Suffice to say, the pre-pluggable version used SwitchView and not PluggableButtonView. -- David Mitchell

When using PluggableButtonView in the way described above the instance created might miss its actionSelector.
The source code could be changed to:


[...]
topView
addSubView: ((PluggableButtonView on: aButton)
label: 'Beep' asParagraph;
insideColor: Color gray;
borderWidth: 1)
viewport: (0@0 corner: 1@1).
[...]


Thus the PluggabbleButtonView will be set to #switch by the instance creation method #on: and the button's onAction-Block will be evaluated whenever the button is pressed -- Harald Liedtke