Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 27th, 2004, 06:15 AM
Authorized User
 
Join Date: Oct 2004
Location: DxB, UAE, United Arab Emirates.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Cute Designer
Default Validate JTextField

<center>Hi dude,

I am stuck in validating the text field, I really wanna know how can I allow a maximum number to be entered in the text field
</center>

Cuty
__________________
~*Cuty*~
Reply With Quote
  #2 (permalink)  
Old November 28th, 2004, 02:30 AM
Authorized User
 
Join Date: Oct 2004
Location: DxB, UAE, United Arab Emirates.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Cute Designer
Default

This is my Code,
                String f = txtFName.getText();
                String l = txtLName.getText();
                String c = txtCode.getText();
                String p = txtPhone.getText();
                String d = taDescribe.getText();
                String t = txtDepartment.getText();
                Object o = cbxOffice.getSelectedItem();
                Object i = cbxImportance.getSelectedItem();
                Object s = cbxStatus.getSelectedItem();
                Object a = cbxAssignTo.getSelectedItem();
                String r = taResolution.getText();

                if (f != null && l != null && c != null && p != null && d != null &&
                o != "--Select country--" && i != "--Select importance--" &&
                i != "--Select importance--" && s != "--Select status--" &&
                a != "--Select resource--")

// if (!(f == null || l == null || c == null || p == null || d == null &&
// o == "--Select country--" || i == "--Select importance--" ||
// i == "--Select importance--" || s == "--Select status--" ||
// a == "--Select resource--"))

// if (!(f == null || l == null || c == null || p == null || d == null))

                {
// System.out.println("Complaint's Info: " + complaintObj.toString());
                    System.out.println("Complaint's info:" + "\n" + "First Name=" + "\t" +
                    f + "\n" + "Last Name=" + "\t" + l + "\n" + "Phone#=" + "\t" + c +
                    " " + p + "\n" + "Department=" + "\t" + t + "\n" + "Description:" +
                    "\t" + d + "\n" + "Office=" + "\t" + o + "\n" + "Importance=" +
                    "\t" + i + "\n" + "Status=" + "\t" + s + "\n" + "Assign to:" +
                    "\t" + a + "\n" + "Resolution=" + "\t" + r + "\n" + "Correct input!");
                }
                else
                    System.out.println("Incorrect input!");
                    JOptionPane.showMessageDialog(null,
                    "Missing input, please enter required info", "Input Error",
                    JOptionPane.ERROR_MESSAGE);

Cuty
Reply With Quote
  #3 (permalink)  
Old November 28th, 2004, 03:05 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You cannot compare strings with =, you have to use .equals:

if (string1.equals("is it equal??"))

Also your if statements do not seem correct, you need {} brackets:

if (string1.equals("???")
{
   if (string2.equals("jklj")
   {
       do something here
   } // close second if statement
} // close first if statement


Reply With Quote
  #4 (permalink)  
Old November 28th, 2004, 03:08 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Regarding limiting the number of characters, Im pretty sure you can get the length of a string.

If you mean set the maximum number, say 10 then use and if statement:

if (number > 10)
{
   generate an error message and reset the field
}

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to validate date jijish ASP.NET 2.0 Professional 4 December 20th, 2007 07:17 AM
Validate form dreamdragon Pro JSP 0 December 11th, 2004 08:11 AM
Setting focus on a JTextField when an applet runs cs21cw Java GUI 1 January 1st, 2004 05:08 PM
Focus Problem with JTextField+InputVerifier mcapote Java GUI 0 July 10th, 2003 10:49 AM



All times are GMT -4. The time now is 10:43 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.