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 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

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
validations - Struts
validations  log in page with validations user name must be special character and one number and remining is alphabetes in struts
Spring Validations
Spring Validations  Hi.. i need code for validations using spring annotations
Validations
Validations
ModuleNotFoundError: No module named 'validations'
ModuleNotFoundError: No module named 'validations'  Hi, My Python... 'validations' How to remove the ModuleNotFoundError: No module named 'validations' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'validations'
ModuleNotFoundError: No module named 'validations'  Hi, My Python... 'validations' How to remove the ModuleNotFoundError: No module named 'validations' error? Thanks   Hi, In your python environment
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
ModuleNotFoundError: No module named 'tripleo-validations'
ModuleNotFoundError: No module named 'tripleo-validations'  Hi, My... named 'tripleo-validations' How to remove the ModuleNotFoundError: No module named 'tripleo-validations' error? Thanks   Hi
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
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
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
ModuleNotFoundError: No module named 'sqlalchemy_elixir_validations'
ModuleNotFoundError: No module named 'sqlalchemy_elixir_validations'  ...: No module named 'sqlalchemy_elixir_validations' How to remove the ModuleNotFoundError: No module named 'sqlalchemy_elixir_validations' error
multiple inheritance.
multiple inheritance.  hello, can java support multiple inheritance???   hi,ADS_TO_REPLACE_1 java does not support multiple inheritance
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  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
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
Add multiple UIBarButtonItem
Add multiple UIBarButtonItem  add multiple uibarbuttonitem
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
TextField validations
TextField validations
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
Struts validations
mail with multiple attachments
mail with multiple attachments  code for sending mail with multiple attachments in jsp
uinavigationcontroller add multiple buttons
uinavigationcontroller add multiple buttons  How to add multiple buttons to the UINavigationController
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
Maven Repository/Dependency: io.swagger | swagger-hibernate-validations
Maven Repository/Dependency of Group ID io.swagger and Artifact ID swagger-hibernate-validations. Latest version of io.swagger:swagger-hibernate-validations dependencies. # Version Release Date
multiple resultset in one resultset
multiple resultset in one resultset  how to retrive multiple resultsets in one resultset in java.? plz help
multiple select values
multiple select values   can you provide an example for multiple select values for html:select tag
insert multiple selection - Java
insert multiple selection - Java  how to insert multiple selection values from html into database using servlets
multiple selections list in Struts
multiple selections list in Struts  How to create a multiple selections list in Struts? and retrive seleted values
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
Remove multiple elements in arraylist
Remove multiple elements in arraylist   how can we remove multiple values in arrayList? only remove method we used for single remove.but i want to delete multiple value in arrayList
struts2 select tag multiple
struts2 select tag multiple  struts2 select tag multiple
multiple choice questions
multiple choice questions  how can i store 10 multiple choice questions in one class with using java language
multiple choice questions
multiple choice questions  how can i implement the program to store multiple questions in class with using core java concepts
multiple submits, single form.
multiple submits, single form.  is it possible to use multiple submit buttons in a single form?   Thank you
select tag multiple values
select tag multiple values   I want to insert multiple values in database which i have selected from select tag
query regarding multiple select
query regarding multiple select  i have a select in jsp with multiple options.When i select multiple values i am not able to insert it into database and how do i retrieve them..please help me with an example code
multiple choice questions program
multiple choice questions program  how can i implement the program to store 10 multiple choice questions in one class to develop a oneline quiz with using java language
multiple choice questions program
multiple choice questions program  how can i implement the program to store 10 multiple choice questions in one class to develop a oneline quiz with using java language

Ads