Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Multiple Validations on jTestFields
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ajay Kumar
Multiple Validations on jTestFields
1 Answer(s)      2 years and 3 months ago
Posted in : Java Beginners


Hi,

I am working on an window application in which I have to validate the data of text fields, like if textbox1 is empty then it prompt for filed should not be empty, and if data is entered then it should check whether it is valid or not. Unless all the validations are not successful in textfield1 it should not move to second text Field.

I have tried it using if Else If ladder but not fulfill, please put an Example ASAP.

Thanks in Advance


Advertisement
View Answers

September 20, 2012 at 6:00 PM


Here is an example that validates single field. You can validate other fields in the same way.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class SwingProgram{
public static void main(String args[]){
SwingProgram p=new SwingProgram();
}
public SwingProgram(){
JLabel label=new JLabel("Enter Name:");
final JTextField text=new JTextField(15);
JButton button=new JButton("Submit");
JFrame f=new JFrame();
f.getContentPane().setLayout(null);
label.setBounds(50,50,80,20);
text.setBounds(150,50,150,20);
button.setBounds(50,80,80,20);
f.add(label);
f.add(text);
f.add(button);
f.setSize(400,150);
f.setVisible(true);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String name=text.getText();
if((name.equals(""))||(name.equals(null))){
JOptionPane.showMessageDialog(null,"Please enter the field","Error",JOptionPane.ERROR_MESSAGE);
}
else{
JOptionPane.showMessageDialog(null,"Welcome "+name);
}
}
});
}
}


Related Tutorials/Questions & Answers:
Multiple Validations on jTestFields
Multiple Validations on jTestFields  Hi, I am working on an window application in which I have to validate the data of text fields, like if textbox1... then it should check whether it is valid or not. Unless all the validations
validations
validations  How to get All Client and server side validations in spring using jsp   Please visit the following link: Spring Validation Example
Advertisements
validations in javascript
validations in javascript  How do you check validations in javascript
Spring Validations
Spring Validations  Hi.. i need code for validations using spring annotations
validations - Struts
validations  log in page with validations user name must be special character and one number and remining is alphabetes in struts
Struts Validations - Framework
Struts Validations  What is the server-side validations exactly? give me on example
Custom Validations - Struts
Custom Validations  Hi, I am trying to do the custom validations in struts 1.1.That is how can we plug in our own custom validations into Validator ? Can anybody tell me how to do this with a sample example. Thanks
struts validations - Struts
struts validations  hi friends i an getting an error in tomcat while running the application in struts validations the error in server as validation disabled plz give me reply as soon as possible.  Hi friend
listbox and textbox validations
listbox and textbox validations  hi, any one please tell me how to set validations for listbox and textboxes using bean classes? thank you   Please visit the following link: http://www.roseindia.net/jsp/user
validations in struts - Struts
validations in struts  hi friends plz give me the solution its urgent I an getting an error in tomcat while running the application in struts validations the error in server as "validation disabled" plz give me reply as soon
Im not getting validations - Struts
Im not getting validations  I created one struts aplication im using DynaValidations I configured validation.xml and validation-rules.xml also in s-c.xml But Im unable to get validations This is my validation.xml file
Javascript validations problem
Javascript validations problem  i have attached two jsp files 1.sports1.jsp and sports.jsp files Here when i run my sports.jsp file my validation works correctly but when my validation fails i am getting an alert window and i am
select box and text box validations
select box and text box validations  hi, any one please tell me how to set validations for select box and text boxes using bean classes? thank you   Please visit the following link: http://www.roseindia.net/jsp/user
Not retriving the validations from validation.xml - Struts
Not retriving the validations from validation.xml  I have create the file called register.jsp    LoginID: Password: when i
java validations
; if (f.length<20) { alert("Address too short"); return false; } var q=document.retailer.contact_no.value; if (q==null || q=="") { alert... q=document.retailer.contact_no.value; if (q==null || q=="") { alert
Locale Specific Date validations through JavaScript/Ajax...
Locale Specific Date validations through JavaScript/Ajax...  Hi, I am developing an JSP Application which supports I18N(Internationalization). In my....), how to manipulate date validations through JavaScript or Ajax? Thanks
multiple inheritance.
multiple inheritance.  hello, can java support multiple inheritance???   hi, java does not support multiple inheritance
Struts: validations code to support 2 date foramats - Struts
Struts: validations code to support 2 date foramats  What is the code in validation.xml to support 2 date formats (DD-MM-YYYY & DD/MM/YYYY ) in form. (I'm using struts 1.3
multiple inheritance
multiple inheritance  Class A extends Class B but Class A also inherit Super Class Object so it is multiple inheritence give reason in support of your answer
multiple inheritance
multiple inheritance  why java doesn't support multiple inheritance? we can achieve this by using interface but not with classes? what is the main reason that java community implemented like
Multiple Inheritance
Multiple Inheritance  All are saying java doesn't support multiple inheritance but by default Object class is super class for all the user defined... class so java any how do multiple inheritance? Can you please explain
Multiple Inheritance
Multiple Inheritance  Why Java Doesn't have Multiple Inheritance It is Advantage or Disadvantage.........   Hi Friend, When we extends... and inconsistencies Java does not support Multiple Inheritance. Thanks
how to perform the client side validations to the dropdown list using javascript?
how to perform the client side validations to the dropdown list using javascript?  Hi Good Morning! This is Prasad, I want to perform the client side validation to the dropdown list using javascript. So give me sample.I am
multiple inhertence
multiple inhertence  package start; class A { protected void a() //a method in A { System.out.println("Class A"); } } class B extends A { public B() { super
multiple inhertence
multiple inhertence  package start; class A { protected void a() //a method in A { System.out.println("Class A"); } } class B extends A { public B() { super
Add multiple UIBarButtonItem
Add multiple UIBarButtonItem  add multiple uibarbuttonitem
 

 

 

DMCA.com