Counter Tutorial with Gtk and GNU Smalltalk

Hi,

In this little tutorial we will build a simple UI. The counter tutorial is just a 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.


The Model

First create a counter class, with an instance variable counter, a method which sets the initial value of the counter, an incrementor and decrementor methods with an converstion method that convert the counter as a string.

" Counter class "

Object subclass: Counter [
    | counter |

    counter: anInteger [
       " setter "

        counter := anInteger
    ]

    counterString [
       " return the counter value as a string "

        ^ counter asString
    ]

    increment [
        " increment the counter and signal that the value as changed "

        counter := counter + 1.
        self changed: #counterString
    ]

    decrement [
        " decrement the counter and signal that the value as changed "

        counter := counter - 1.
        self changed: #counterString
    ]
]


The User Interface

Now we will create the application window and the differents widgets inside it:

    | 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

Keranjangmovie.com
Keranjangbokep.com

Berita Prediksi Bola - http://www.ajangprediksi.com/

download video di http://stafa.vizee.co

Download lagu di viloza http://www.viloza.info

Download video di http://www.vizee.co
Download lagu di http://www.wapuza.com

http://en.fleble.com/ english version
http://en.fleble.com/populer popular english version
http://en.fleble.com/index index english

http://Fleble.com Cara Cepat Baca Berita Berkualitas!
http://fleble.com/populer pencarian topik berita terpopuler fleble.com
http://fleble.com/index index berita terkini fleble.com

Nonton Film Movie Cinema Bioskop 21 ==> http://bioskop21.id - http://bioskop21.mobi - http://bioskop21.co - http://movie25.link - http://ganool.nl

jadwal film bioskop 21 terbaru ==> http://www.jadwal21.info

http://www.vidio.com/@bioskop21id
http://www.vidio.com/bioskop21id
http://bioskop21co.blogspot.com/2015/12/4-situs-nonton-film-bioskop-21-o...
http://bioskop21co.wikidot.com
http://nontonfilmonlinebioskop21.yolasite.com
http://bioskop21co.livejournal.com/757.html
http://www.reddit.com/r/movies/comments/3yzewa/bioskop21co_situs_terbaik...
http://delicious.com/bioskop21co
http://youtu.be/QRhRV09k_WY
http://www.plurk.com/ganool168
http://forum.nontonhbo.net
http://blondin.info
http://bioskop21.co
http://bioskop21.id
http://bioskop21.mobi
http://nontonfilmonline.top
http://movie25.link
http://tv.bioskop21.id
http://goo.gl/FmM4br
http://film-war.net
http://film21.in
http://ganool.nl
http://ganool168.org
http://www.bioskop21.info
http://nontonhbo.com
http://bioskop-21.com
http://nontonfilmhbo.com
http://nonton-filmonline.com
http://nontonfilm-online.com
http://ganool.be
http://kaskus.eu
http://filmbioskop.my.id
http://nontonhbo.net
http://fadly168.com
http://fadly168.net
http://fadly168.my.id
http://fadly168.ga
http://filmbioskop.at.ua
http://bokep168.me
http://ceritadewasa.co.uk
http://obatkuatsex.info
http://obatkuatku.us
http://dpbbmterbaru.link
http://jilbabcantik.link
http://paketinternet.link
http://makassar.link
http://nontonfilm21.link
http://bioskop21.link
http://ceritadewasa.asia
http://wp.me/6Xads
http://makassarkini.com
http://www.google.com/+Makassarkini
http://dengarlagu.top
http://er-music.top
http://vmax-id.top
http://makassarwebs.com

Nonton Film Movie Cinema Bioskop 21 ==> http://bioskop21.id - http://bioskop21.mobi - http://bioskop21.co - http://movie25.link - http://ganool.nl

jadwal film bioskop 21 terbaru ==> http://www.jadwal21.info

berita terkini dan terpopuler di http://britau.com
indeks berita terkini di http://britau.com/index
nonton siaran langsung bola online di http://nobartv.com
nonton siaran tv streaming online di http://nobartv.com/tv-online
nonton jadwal siaran langsung live streaming liga inggris di http://nobartv.com/jadwal/9/liga-inggris
nonton jadwal siaran langsung live streaming liga italia di http://nobartv.com/jadwal/1/serie-a-italia
nonton live streaming siaran bein sports 3 di http://nobartv.com/tv-online/1/81/Bein-Sports-3
indeks berita bola terkini hari ini di http://nobartv.com/index-berita
kabar berita bola terkini dan terbaru di http://nobartv.com/beritabola
komunitas sepak bola online indonesia di http://soccerio.net

User login