Validation in swing

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.
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.
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
Advertisements
validation - Swing AWT
by creating an object of another existed java swing class.As we have used the class
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
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
SWING
SWING  A JAVA CODE OF MOVING TRAIN IN SWING
validation
validation  validation
swing
swing  Write a java swing program to delete a selected record from a table
swing
swing  How to make swing component auto-resizable when JFrame resize
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
validation
validation  we are doing payroll system project in java.So pls provide the complete validation code for employee master form
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
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
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.....  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 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
java swing - Swing AWT
java swing  how i can insert multiple cive me exampleolumn and row in one JList in swing?plz g  Hi Friend, Please clarify your question. Thanks
swing-awt - Swing AWT
swing-awt  Hi, Thanks for replying to my question...I'm getting some confusion to add action events in my application(Rich Text Editor).How to add action events? Thank U
What is Swing?
What is Swing?  What is Java Swing? Where to get the tutorials of Swing? I am beginner in Java Swing programming and trying to find the tutorials of Swing. Tell me the urls to learn swing. Thanks   Hi, Swing is Java
swing/awt - Swing AWT
swing/awt  How to create richtexteditor using swings...?I'm very much new to swings....It's urgent.....Thank u...   hello read this book you get idea; JFC Swing Tutorial, The: A Guide to Constructing GUIs, Second
Swing paint - Swing AWT
Swing paint  hi, i want to print something on window using swing applet.. m doing dis.. protected void paintComponent(Graphics g... the Swing Applet, use html file with the following code: Java Applet Demo
swing sms
swing sms  HOW TO SEND SMS MESSAGE FROM SWING USING SQL DATABASE
Swing Program
Swing Program  Write a java swing program to calculate the age from given date of birth
SWING FRMES
SWING FRMES  hai SIR? HOW TO DESIGN swing Frames send source code
SWING FRMES
SWING FRMES  hai SIR? HOW TO DESIGN swing Frames send source code
swing to applet
swing to applet  hi how i can isplay a java swing into applet java thanks
java swing - Swing AWT
java swing   how i can insert in JFrame in swing?  Hi Friend, Try the following code: import java.awt.*; import javax.swing.*; import java.awt.event.*; class FormDemo extends JFrame { JButton ADD; JPanel
java swing - Swing AWT
java swing  how to add image in JPanel in Swing?  Hi Friend, Try the following code: import java.awt.*; import java.awt.image....: http://www.roseindia.net/java/example/java/swing/ Thanks
AWT & SWING
AWT & SWING  What is diffennce between AWT & SWING
Jva swing
Jva swing   How to create the model form like "Notepad
Java swing
Java swing  what are the root classes of all classes in swing
Java swing
Java swing  Does Swing contains any heavy weight component
java swing
java swing  view the book details using swing
printing in swing
printing in swing  How can i print payslip in swing
swing program
swing program  Write a java swing program to getname and email id. Display the message if email id contains the name of theuser
SWING - Swing AWT
SWING  how can i insert image in Jpanel by extending class with JFrame in swing?  Hi Friend, Try the following code: import java.awt.*; import java.awt.image.*; import java.io.*; import javax.imageio.*; import
java swing - Swing AWT
java swing   Iam developing a java web browser.Actually my code works fine ie. i can load a web page without proxy.But in my place i have only proxy servers through which i should visit any web site.So, i want my browser also
Swing Program
Swing Program  write a java swing program to get username and password. The name contains only characters while password is masked with the characters "*". Apply checks for all validation.   import javax.swing.*; import
swing - Swing AWT
swing   how to create JTabbedPane.when i choose one jtabbedpane it will appear JTextField,resultMessages.pls give me any examples  Hi Friend, Try the following code: import javax.swing.*; import java.awt.
SWING - Swing AWT
SWING  how to insert image and components such as JLabel,JButton,JTextfield in JFrame in swing?  Hi Friend, Try the following code: import java.io.*; import java.awt.*; import javax.swing.*; import
Swing question - Swing AWT
Swing question  I want to move a string in JFrame similarily as done by marquee tag in HTML.The string should move from right to left. How can I do this?  Hi Friend, Try the following code: import java.awt.
Swing application
Swing application  Hello, I want to develop a Swing application similar to J2EE application.The only difference is that, the users will access the application not through web browsers, instead through a Swing desktop application
java swing
java swing  what is java swing   Swing is a principal GUI toolkit for the Java programming language. It is a part of the JFC (Java... the following link: Swing Tutorials
java swing
java swing  how to connect database with in grid view in java swing   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 Grid view in java swing Thanks
swing with jdbc - Swing AWT
swing with jdbc  Hi, i m developing the desktop application using swing.i want to use table structure for that.also its DB specific application. i have some problems with swing using jdbc. 1. the values entered in table
java - Swing AWT
java  how can i validate textfield in swing?  Hi Friend... java.awt.event.*; import java.util.regex.*; class Validation extends JFrame{ JTextField text; JLabel l1,l2; JPanel p; Validation(){ text=new
java swing
java swing  add two integer variables and display the sum of them using java swing

Ads