Skip to content

Instantly share code, notes, and snippets.

@timyates
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timyates/d97d613e4379434ff7a8 to your computer and use it in GitHub Desktop.
Save timyates/d97d613e4379434ff7a8 to your computer and use it in GitHub Desktop.
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