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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


prathima
Swings
2 Answer(s)      5 years ago
Posted in : Java Beginners



Advertisement
View Answers

December 11, 2009 at 11:40 AM


Hi Friend,

Try the following code:

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

public class newuser extends JFrame{
private JLabel jLabel1;
private JLabel jLabel2;
private JLabel jLabel3;
private JLabel jLabel4;
private JLabel jLabel5;
private JLabel jLabel6;
private JTextField jTextField1;
private JTextField jTextField2;
private JTextField jTextField3;
private JTextField jTextField4;
private JTextField jTextField5;
private JPasswordField jPasswordField1;
private JButton jButton1;
private JPanel contentPane;
private JLabel l1,l2,l3,l4,l5,l6;
public newuser(){

jLabel1 = new JLabel();
jLabel2 = new JLabel();
jLabel3 = new JLabel();
jLabel4 = new JLabel();
jLabel5 = new JLabel();
jLabel6 = new JLabel();
jTextField1 = new JTextField();
jTextField2 = new JTextField();
jTextField3 = new JTextField();
jTextField4 = new JTextField();
jTextField5 = new JTextField();
jPasswordField1 = new JPasswordField();
jButton1 = new JButton("Submit");
l1 = new JLabel("*Please Enter First Name");
l2 = new JLabel("*Please Enter Last Name");
l3 = new JLabel("*Please Enter Present Address");
l4 = new JLabel("*Please Enter Permanent Address");
l5 = new JLabel("*Please Enter Email Id");
l6 = new JLabel("*Please Enter Password");
contentPane = new JPanel(new GridLayout(7,3));
jLabel1.setText("First name");
jLabel2.setText("Last name");
jLabel3.setText("Present address");
jLabel4.setText("Permanent Address");
jLabel5.setText("Email id");
jLabel6.setText("password");


contentPane.add(jLabel1);
contentPane.add(jTextField1);
contentPane.add(l1);
contentPane.add(jLabel2);
contentPane.add(jTextField2);
contentPane.add(l2);
contentPane.add(jLabel3);
contentPane.add(jTextField3);
contentPane.add(l3);
contentPane.add(jLabel4);
contentPane.add(jTextField4);
contentPane.add(l4);
contentPane.add(jLabel5);
contentPane.add(jTextField5);
contentPane.add(l5);
contentPane.add(jLabel6);
contentPane.add(jPasswordField1);
contentPane.add(l6);
contentPane.add(jButton1);

l1.setVisible(false);
l2.setVisible(false);
l3.setVisible(false);
l4.setVisible(false);
l5.setVisible(false);
l6.setVisible(false);


add(contentPane);
pack();
setVisible(true);


jButton1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
String Firstname = jTextField1.getText();
String Lastname = jTextField2.getText();
String presentaddress = jTextField3.getText();
String permanentaddress= jTextField4.getText();
String Emailid = jTextField5.getText();
String Password = jPasswordField1.getText();


December 11, 2009 at 11:40 AM


continue...

if(Firstname.equals("")){
l1.setVisible(true);
l2.setVisible(false);
l3.setVisible(false);
l4.setVisible(false);
l5.setVisible(false);
l6.setVisible(false);
l1.setForeground(Color.RED);
}
else if(Lastname.equals("")){
l1.setVisible(false);
l2.setVisible(true);
l3.setVisible(false);
l4.setVisible(false);
l5.setVisible(false);
l6.setVisible(false);
l2.setForeground(Color.RED);
}
else if(presentaddress.equals("")){
l1.setVisible(false);
l2.setVisible(false);
l3.setVisible(true);
l4.setVisible(false);
l5.setVisible(false);
l6.setVisible(false);
l3.setForeground(Color.RED);
}
else if(permanentaddress.equals("")){
l1.setVisible(false);
l2.setVisible(false);
l3.setVisible(false);
l4.setVisible(true);
l5.setVisible(false);
l6.setVisible(false);
l4.setForeground(Color.RED);
}
else if(Emailid.equals("")){
l1.setVisible(false);
l2.setVisible(false);
l3.setVisible(false);
l4.setVisible(false);
l5.setVisible(true);
l6.setVisible(false);
l5.setForeground(Color.RED);
}
else if (Password.equals("")) {
l2.setVisible(false);
l3.setVisible(false);
l4.setVisible(false);
l5.setVisible(false);
l6.setVisible(true);
l6.setForeground(Color.RED);
}
else{
l1.setVisible(false);
l2.setVisible(false);
l3.setVisible(false);
l4.setVisible(false);
l5.setVisible(false);
l6.setVisible(false);
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root";);
Statement stmt=con.createStatement();
stmt.executeUpdate("insert into register(fname,lname,presentaddress,permanentaddress,emailid,password) values ('"+Firstname+"','"+Lastname+"','"+presentaddress+"','"+permanentaddress+"','"+Emailid+"','"+Password+"')");
System.out.println(" registration is cmptd successfully!");
stmt.close();
}
catch (Exception ex)
{
System.out.println("Failed loading L&F: ");
System.out.println(ex);
}


}
}
});
}


public static void main(String[] args)
{
newuser user=new newuser();

}



}

Thanks


Related Tutorials/Questions & Answers:
SWINGS
SWINGS  WHAT ARE THE DIFFERENCES BETWEEN AWT AND SWINGS
JSP & Swings
JSP & Swings  How to integrate jsp and swings
Advertisements
swings question
swings question  how to change the background color with the help of color values by using swings
swings for webnms
swings for webnms  if i am expanding node of jtree then i want to collapse previous expanding node of jtree in swings how is it possible
Swings JTable
Swings JTable  add values to JTable with four coloums,two of them are comboboxes
Swings & JSP
Swings & JSP  Hai all, Can we use Swing components in a JSP?? Suppose if we enter details in a swing dialog box..and If we want the result in a JSP..is that possible??? Thank you
Java Swings
Java Swings  I am doing one project on java Swings, in this i have created one jframe where i defined some JButtons and Jcombobox's, here i need to insert one JTable with headers(IN CURRENT JFrame only).pls help me urgently
swings header
swings header   have a string1 it contains 3 parts,for example "123456 service hello" and string2 contains text "change request " like this. and the string3 should contain "123456 +(second string)+ hello" "second string can
swings
","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}; for(i = 0
Swings and JDBC
Swings and JDBC  Hi.. I am vinay.. I am developing a small application using swings and mysql. I am sending part of the code here.. The problem is i need to update the mysql fields with values which are gettin from dynamiclly
Swings - Applet
Swings  Sir, I have developed an application in swings i want to call that class in applet. is it possible. or otherwise is there any way to deploy java class in browser. Give an example... Thanks in advance...  Hi
how to create frame in swings
how to create frame in swings  how to create frame in swings
Image Movement using Swings
Image Movement using Swings  How to move image using Swings
java swings - Java Beginners
java swings   Do you want to add textfields on the JPanel
Swings/awt - Swing AWT
Swings/awt  Hi, how to write action listeners to the Buttons in RichTextEditor tool bar.. thanks in advance...it's Urgent... i am very much new to Swings
java code using swings
java code using swings  code that should be able to enter data of student details using all swings into the access database using jdbc connectivity
java swings - Java Beginners
java swings   Hi, I need the code for click the refresh button then list values will be refresh.Please send the code ........... Thanks, Valarmathi
An application using swings and vector methods
An application using swings and vector methods   Hi, I want an application in Java swings which uses good selection of Vectors methods
about swings - Java Beginners
about swings   Dear sir,Good evening, i am doing mca sir,i am doing the project in swings,so plz provide the material about swings sir Thank you  Hi Friend, Please visit the following link
java swings - Java Beginners
java swings   Hi, I need the code for joptionpane with jcombobox. my requirement is click on add button,one joptionpane will come.from the option pane i need to select the combobox values. Please send the sample code
swings window header
swings window header  i have a string1 it contains 3 parts,for example "123456 service hello" and string2 contains "change request " like this. and the string3 should contain "123456 "........." hello" ".........." can
java swings - Swing AWT
java swings  I am doing a project for my company. I need a to show the performance of the employees by using bar bharts. Please give me how can we write the code for bar charts using java swings.  Hi friend, I am
another frame by using awt or swings
another frame by using awt or swings  how to connect one frame to another frame by using awt or swings
making of dynamic textfields using swings
making of dynamic textfields using swings  How to make dynamic textfields using java swings
how can we store the encrypted passwaord in swings?
how can we store the encrypted passwaord in swings?   how can we store the encrypted passwaord in swings
 

 

 

DMCA.com