Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 27th, 2004, 06:15 AM
Authorized User
 
Join Date: Oct 2004
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*~
 
Old November 28th, 2004, 02:30 AM
Authorized User
 
Join Date: Oct 2004
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
 
Old November 28th, 2004, 03:05 PM
Friend of Wrox
 
Join Date: Jul 2004
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


 
Old November 28th, 2004, 03:08 PM
Friend of Wrox
 
Join Date: Jul 2004
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
}






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





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