Skip to content

Instantly share code, notes, and snippets.

@timyates

timyates/Counter.groovy

Last active Aug 29, 2015
Embed
What would you like to do?
7guis counter
import javafx.geometry.Insets
import static groovyx.javafx.GroovyFX.start
start {
stage(title: 'Counter', show: true, onHidden:{e -> System.exit(0)}) {
scene {
hbox(spacing:10, padding:new Insets(10)) {
textField(id: 'count', editable: false, prefColumnCount: 10, text:'0')
button('count', onAction:{e -> count.text = (count.text as Integer) + 1})
}
}
}
}
// Or, with binding:
import javafx.geometry.Insets
import groovyx.javafx.beans.FXBindable
import static groovyx.javafx.GroovyFX.start
class Model {
@FXBindable String clicksStr = "0"
private int clicks = 0
def onClick = {
clicksStr = "${++clicks}"
}
}
start {
def model = new Model()
stage(title: 'Counter', show: true, onHidden:{e -> System.exit(0)}) {
scene {
hbox(spacing:10, padding:new Insets(10)) {
textField(id: 'count', text:bind(model.clicksStrProperty), editable: false, prefColumnCount: 10)
button('count', onAction:model.onClick, focused: true)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.