Both of these are called event handlers so when the contents of the textfield1 changes an event is fired and these methods catch the event and process it.
void handleTextEvents(GEditableTextControl source, GEvent event) {
// ...
}
and
public void textfield1_change1(GTextField source, GEvent event) {
// ...
}
The difference is the first one is will handle events from all text controls so you have to test the source
to decide what to do. The second one is associated with a particular control, in this case the GTextField
object textfield1
and is created by GUI Builder with the following statement which you can see in the gui tab.
textfield1.addEventHandler(this, "textfield1_change1");
So the user has the option of using the generic text event handler or overriding it by adding an event handler specific to the control with addEventHandler
.
OK so the above is just to explain the difference between the 2 event handlers so we come to this
To make a GTextField validate numeric input we need to do something extra, so in customGUI() add the line
textfield1.setNumeric(-100.0, 100.0, 0);
this will make the control (created in GUI Builder) validate numeric input, in this case numbers between -100 and +100 starting value 0.
Unfortunately you canât set this in GUI Builder itself since this and GSpinner are very new updates that are not shown in GUI Builder yet.
There are different types of text event so we need to filter the event to get the one we want
public void textfield1_change1(GTextField source, GEvent event) {
if (event == GEvent.ENTERED) { // Enter key has been typed
float n = source.getValueF();
println(n);
}
}
I think that covers your question.