We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm working on a program that takes a grid of numbers as inputs. I'd like to use GTextField objects to enter each number. As far as I can tell, there's no easy way to limit the possible characters to the digits 0-9 only. I think I know how to make an event handler that's called whenever a text field changes, and simply deletes any wrong characters. The problem I'm running into here is that I'd need to find a way to scale this to work with multiple text fields. I would prefer not to have a separate event handler for each text field, as this would result in many copies of the same code, just with different method names. Any suggestions how I could go about doing this?
Answers
I don't know how you could do that with GTextField. A post from two years ago describes a way to do it:
s an alternative, you could use controlP5 by using:
You can check an example and the reference in the following links:
This is just an idea.
Kf
My approach to this problem has changed slightly. I now have the event handler coloring the text in the textField red if there is an invalid character or the value is out of range. The issue with having a separate event handler for each textField turned out to be a misunderstanding on my part. I didn't realize/didn't know that multiple events could call the same handler, and the textField that caused the call would be passed to the handler as its first argument. That allows me to call any method on whichever textField the event came from, which is exactly what I needed in the first place.