1 Replies - 1221 Views - Last Post: 24 March 2012 - 11:07 AM Rate Topic: -----

#1 robgw3   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 138
  • Joined: 23-February 12

Need help with text field validation

Posted 24 March 2012 - 10:57 AM

Ok i have a project for my java course that i need to finish, but part of it is creating a class that can validate the text that is entered into a text field. The purpose of this is to make sure that a user can only enter a number from 0-9 into the text field (yes i know it is so much easier just to make it a formatted text field and remove that problem altogether, but this is part of the project). The thing is that the instructor included a UML diagram for the class we are supposed to make for this text field validator, and i dont understand it at all. So could someone help me understand this so i can make the class?

===========================================================================

TextFieldValidator
-regExp : String = "\\w"
-errorColor : Color = Color.RED

+TextFieldValidator(in myTarget : JTextField, in myColor : Color)
+TextFieldValidator(in myTarget : JTextField)
+setRegExp(in myRegExp : String)
+setErrorColor(in myColor : Color)
+check() : Boolean

> Class Notes
The idea behind this class is to provide a robust and useful tool
for validating all input entered into a textfield (JTextField object)
on a java frame (window).
When a TextFieldValidator object is first constructed it will
require the textfield it is to validate. The check method will then
test any input of the textfield against a provided regular
expression and return the result. It will also change the border
color of the textfield to a specified errorColor if the input does
not validate.
Through the UML you can clearly see the basic structure of the
TextFieldValidator class and the properties and methods
required. Note that only private variables are outlined in the
class diagram that exist to hold values of properties. There will
be the need to add other private variables to support your
internal class coding.

=========================================================================

The top part with Text Field Validator was in a table on the sheet he gave us, i guess "TextFieldValidator" is supposed to be the class name, but thats about all i really understand about the UML diagram. I recently used regular expressions to change any occurance of a word in text typed into a text box to a different word so that i know how to do, but the regExp line i dont understand what it's saying there.

Is This A Good Question/Topic? 0
  • +

Replies To: Need help with text field validation

#2 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: Need help with text field validation

Posted 24 March 2012 - 11:07 AM

Quote

-regExp : String = "\\w"
-errorColor : Color = Color.RED

These are the instance fields for the class. The - symbol indicates they should be private.

Quote

+TextFieldValidator(in myTarget : JTextField, in myColor : Color)
+TextFieldValidator(in myTarget : JTextField)
+setRegExp(in myRegExp : String)
+setErrorColor(in myColor : Color)
+check() : Boolean

Here are your methods for the class. The + indicates that they should be public. Remember that methods named the same as the class are constructors, and methods without explicit return types should return void.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1