Hi,
The counter tutorial is a simple window with two buttons and a label;
we will see how to add widgets in the main window and how to handle the
Gtk events.
" We still need to load the Gtk-Tools package "
PackageLoader fileInPackage: 'GtkTools'.
" Counter class "
Object subclass: Counter [
| counter |
counter: anInteger [
<category: 'accessing'>
" the setter "
counter := anInteger
]
counterString [
<category: 'accessing'>
" return the counter value as a string "
^ counter asString
]
increment [
<category: 'increment'>
" increment the counter and signal that the value as changed "
counter := counter + 1.
self changed: #counterString
]
decrement [
<category: 'decrement'>
" decrement the counter and signal that the value as changed "
counter := counter - 1.
self changed: #counterString
]
]
| b1 b2 counter label frame window |
" The window "
window := GtkTools GtkMainWindow new.
" The counter with an initial value set to 0 "
counter := Counter new
counter: 0;
yourself.
" The layout where widgets will be displayed "
frame := GTK GtkFixed new.
" A new button "
b1 := GTK GtkButton labeled: '+'.
" Send the increment message to counter when the user click
on the button "
b1 onClick: #increment to: counter.
" Add the button to the frame "
frame at: 50@20 put: b1.
" A new button "
b2 := GTK GtkButton labeled: '-'.
" Send the decrement message to counter when the user click
on the button "
b2 onClick: #decrement to: counter.
" Add the button to the frame "
frame at: 50@80 put: b2.
" The label "
label := GTK GtkLabel new: '0'.
" Update the label when counter update its value "
label refreshFrom: #counterString for: counter.
frame at: 190@58 put: label.
window
centralWidget: frame;
title: 'simple';
statusMessage: 'Simple GTK Application';
" Set the application size "
resize: 230@150;
" Set the application icon "
icon: (GTK.GdkPixbuf fromFile: 'visualgst.png');
showAll.
counter increment.
GTK Gtk main
Cheers,
Gwen
_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk