Wednesday Sep 17, 2008

Further Experiments with Griffon

Another small experiment with Griffon, but this time there's a problem, one that I've had a couple of times. First, the code. Here's the model:

import groovy.beans.Bindable

class App1Model {

    @Bindable String name = "James"

}

Here's the controller:

class App1Controller {

    def model
    def view

    def saveName = { evt ->
        model.name = view.nameField.text
    }

}

Here's the view:

build(App1Actions)

application(title: 'App1', size:[320,480],
    location:[50,50], pack:true, locationByPlatform:true) {

    panel(border:emptyBorder(6)) {
        borderLayout()
        hbox(constraints:NORTH) {
            label(text:"Name:")
            hstrut(5)
            textField(id:"nameField",columns:20,"Tom")
            hstrut(5)
            button(action: saveName)
        }
        hbox(constraints:SOUTH) {
            label(text: "Hello ")
            label(text: bind{model.name})
        }
    }

}

And here's the "App1Actions" that's referred to above:

actions {

    action( id: 'saveName',
        name: "Save",
        closure: controller.saveName,
        accelerator: shortcut('S'),
        mnemonic: 'S',
        shortDescription: "Save the entered name",
    )

}

Couldn't be much simpler than that. The text in the label is bound to the domain 'name', which changes when the Save button is clicked. I then deployed both the Swing application and the applet (which, for fun, I dragged out of the browser):

But there's a problem. The Swing application works as expected. But the applet only works the first time the Save button is clicked, after that not at all. Possibly there's a threading issue? Or an initialization issue? I didn't use any of the lifecycle classes. Maybe that's why? Anyway, I'm stumped.

About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« September 2008 »
SunMonTueWedThuFriSat
 
3
6
9
13
14
23
30
    
       
Today