Details
-
New Feature
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.0-beta-4
-
None
-
None
Description
Right now there does not seem to be any support for attaching event handlers to components via the SwingBuilder class. Some kind of support should be added to make hooking up logic to components easier.
Here are two initial ideas:
1 - Provide attributes for components similar to HTML forms:
builder.frame( onWindowFocusGain:
{println "I am focused"}onMouseClicked:
{println "Clicked: " + it.clickCount})
Pro: A common approach that is easy for people to understand.
Con: Not the most modular an extensible. Does not match the Java model for GUI event handling.
2 - seperate constructs for creating event handlers
builder.frame() {
windowEvents( closing:
{ System.exit() },
focusGained:
)
mouseEvents( clicked:
{ println "Clicked: " + it.clickCount })
// Adds a static handler
keyEvents( static: new MyKeyEventHandler() )
// No reason not to add two handlers
keyEvents( typed:
)
}
Pro: Easier to abstract and make extensible for new event types. Closer to Swing model for event handling. Convinient grouping of handlers.
Con: Not intuitive to web programmers. Requires more coding.