restricting text and forcing UPPERCASE in an applet
I have an applet where the users can enter anything into a text field. I would like to restrict user input to "Y" and "N" only. Also I would like them to be able to enter"y" and the text is converted into uppercase "Y". I'm using Sun One studio to develop in
Thanks for any help
You can use the toUpperCase function of strings to convert everything to uppercase. Just take their text and use the fnction, Eg:
String upperCase = theirText.toUpperCase();
Hope this helps!
if you are using JDK 1.4 you could try to see if JFormattedTextField will do what you wish.
Otherwise, perhaps implement a textListener to activate when the content of the text field changes and if the text entered is not y/Y or n/N you can set it back to empty string and as MasterOfSouls stated, you can use str.toUpperCase()
Laziness is a virtue.
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL