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



Home Answers Viewqa Java-Beginners Validation in swing
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ragavan
Validation in swing
2 Answer(s)      4 years and 11 months ago
Posted in : Java Beginners


I want to validate my swing program. If I didnt enter the field in text box a msgbox should have to appear that enter all the fields.

Advertisement
View Answers

February 3, 2010 at 2:47 PM


Hi Friend,

Try the following code:

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);
}
}
});
}
}

Thanks


January 29, 2011 at 1:24 PM


i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name and password and the submit button.. when i click the submit button it has to check the user name and password from the data base.. please help me for the code..



Related Tutorials/Questions & Answers:
Validation in swing - Java Beginners
Validation in swing  I want to validate my swing program. If I didnt enter the field in text box a msgbox should have to appear that enter all the fields.  Hi Friend, Try the following code: import java.awt.
validation - Swing AWT
by creating an object of another existed java swing class.As we have used the class
Advertisements
how to give validation using javascript in swing
how to give validation using javascript in swing   how to give validation using javascript in swing....... can somebody give code for username and password validation using javscript and swing
JTable Cell Validation? - Swing AWT
JTable Cell Validation?  hi there please i want a simple example...(table); JLabel label=new JLabel("JTable validation Example",JLabel.CENTER...=new JFrame("JTable validation"); frame.add(label,BorderLayout.NORTH
validation
validation  validation
JTextField Validation in java swing
JTextField Validation in java swing In this tutorial, you will learn how to validate jtextfield in java swing. Here we have created a textfield on frame and allowed the user to enter. If the user enter characters or symbols or special
validation
validation  we are doing payroll system project in java.So pls provide the complete validation code for employee master form
validation.....
validation.....  hi.......... thanks for ur reply for validation code. but i want a very simple code in java swings where user is allowed to enter only numerical values in textbox , if he enters string values then it should
Validation
Validation  Hi.. How to Validate blank textfield in java that can accepts only integers?   Have a look at the following link: http://www.roseindia.net/tutorial/java/swing/howtovalidatetextfield.html
validation
Validation method valid the in put. otherwise call the javascript onsubmit to check... code.Ok if you use struts then you can use Validation method valid the in put
Validation
); JLabel label=new JLabel("JTable validation Example",JLabel.CENTER); JPanel panel=new JPanel(); panel.add(scroll); JFrame frame=new JFrame("JTable validation
validation
validation  please help me to check validation for <form> <table class="form"> <tr> <td class="col1"> <label>Sno:</label> </td> <td
SWING
SWING  A JAVA CODE OF MOVING TRAIN IN SWING
swing
swing  How to make swing component auto-resizable when JFrame resize
swing
swing  Write a java swing program to delete a selected record from a table
Swing
Swing  Write a java swing program to search the details of the students. Searching is performed on studentā??s first name. The details of all those students having same name as in given in searching criterion will be displayed
Swing
Swing  Write a java swing program to search the details of the students. Searching is performed on studentā??s first name. The details of all those students having same name as in given in searching criterion will be displayed
Swing Program
Swing Program  write a java swing program to get user name and password. The name contains only characters while password is masked with the character "*". Apply checks for all validation
Swing Program
Swing Program  Write a java swing program that takes name and marks as input with all validation. The name and marks will be displayed in message box when user clicks on a button
validation files
validation files  If I place validation files in the folder where the action classes are present,will there any error arise
javascript validation
javascript validation  validation of comparing dropdownlist and textbox in javascript
NSURL Validation
NSURL Validation  How to validate a NSURL string using special character validation
form validation
form validation  how the form validation is done in jsf form using javaScript
validation query
validation query  where I should kept properties file inside struts Web application
Validation - Struts
Validation  what is the best way to use validation in Struts?either "validation.xml" or JavaScript
email validation
email validation  during email validation.... after domain name which it means if example example@gmail.co .... this address allowed by any validation program .... but i want to show invalid email address because domain name com
Validation of datepicker
Validation of datepicker  I have a datepicker in my JSp...the seleted dates are put in a text box. I want the alert the user from selecting future... a future date is entered..How to do this validation in javascript or jsp
email validation
email validation  during email validation.... after domain name which it means if example example@gmail.co .... this address allowed by any validation program .... but i want to show invalid email address because domain name com
comboBox validation
comboBox validation  dear sir. i want to know . how to validate radio button in struts using xml validation. thanks
Date Validation
Date Validation  Hi, I need Date Validation using java in spring framework. Please Anyone help me... Thanks in advance
Form Validation
Form Validation  Java script validation for checking special characters and white spaces and give an alert.Please help me urgent Thanks in advance
 

 

 

DMCA.com