swing login code

swing login code

code for the login form..

View Answers

January 29, 2011 at 1:06 PM

Hi Friend,

Try this:

1)LoginDemo.java:

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

class LoginDemo extends JFrame{
 JButton SUBMIT;
 JLabel label1,label2;
 final JTextField  text1,text2;
  LoginDemo(){
    setTitle("Login Form");
    setLayout(null);
    label1 = new JLabel();
    label1.setText("Username:");
    text1 = new JTextField(15);

    label2 = new JLabel();
    label2.setText("Password:");
    text2 = new JPasswordField(15);

    SUBMIT=new JButton("SUBMIT");
    label1.setBounds(350,100,100,20);
    text1.setBounds(450,100,200,20);
    label2.setBounds(350,130,100,20);
    text2.setBounds(450,130,200,20);
    SUBMIT.setBounds(450,160,100,20);
   add(label1);
   add(text1);
   add(label2);
   add(text2);
   add(SUBMIT);

   setVisible(true);
   setSize(1024,768);

 SUBMIT.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent ae){
    String value1=text1.getText();
    String value2=text2.getText();
    try{
 Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from login where username='"+value1+"' and password='"+value2+"'");
           String uname="",pass="";
           if(rs.next()){
               uname=rs.getString("username");
               pass=rs.getString("password");
           }
 if(value1.equals("") && value2.equals("")) {
      JOptionPane.showMessageDialog(null,"Enter login name or password","Error",JOptionPane.ERROR_MESSAGE);
  }
 else if(value1.equals(uname) && value2.equals(pass)) {
    NextPage page=new NextPage(uname);
    page.setVisible(true);
    }
 else if (!value1.equals(uname) && !value2.equals(pass)) {
     text1.setText("");
     text2.setText("");
    }
    }
    catch(Exception e){}
}
 });
  }

  public static void main(String arg[]){
  new LoginDemo();
}
}

2)NextPage.java:

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

class NextPage extends JFrame
{
  NextPage(String st)
   {
      setLayout(null);
     setDefaultCloseOperation(javax.swing. WindowConstants.DISPOSE_ON_CLOSE);
     setTitle("Welcome");
     JLabel lab=new JLabel("Welcome  "+st);

     lab.setBounds(10,10,500,20);
     add(lab);

       setSize(1024, 768);
      }
 }

Thanks


October 1, 2012 at 11:02 AM

thanks man it was useful for me :)









Related Tutorials/Questions & Answers:
swing login code
swing login code  code for the login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Advertisements
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
php login and logout code
php login and logout code  Hi, Can anyone share there code for creating a user login and logout page in PHP?or any useful tutorial that can help to create a login and logout application in PHP.. Thanks in Advance
login page code in asp.net
login page code in asp.net  i need front end and backend code for login page in vb asp.net using sql server....having code for submit button
code for login fom - Struts
code for login fom  we have a login form with fields USERNAME: PASSWORD: In this admin can login and also narmal uses can log
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form... label1,label2; final JTextField text1,text2; LoginDemo(){ setTitle("Login
SWT login form - Swing AWT
SWT login form  Hi, I want code to create a login form in SWT. My requirement is that when the user clicks "enter" button from keyboard "login..., Code to solve the problem : import org.eclipse.swt.SWT; import
HTML login page code
the complete HTML JavaScript code for User Login Page. Thanks in Advance!   ...HTML login page code  Hi all, I am writing my first HTML JavaScrip...: " + form.pwd1.value); return true; }   html registration form code
code - Swing AWT
code  i want example problem for menubar in swings  Hi Friend, Please visit the following links: http://www.roseindia.net/java/example/java/swing/SwingMenu.shtml http://www.roseindia.net/java/example/java/swing
what is the code for login page in html
what is the code for login page in html  Hi, I am total beginner in HTML coding. I want to make a login page in HTML to understand the form coding. I think login page is goot topic to start and learn. what is the code for login
what is the code for login page in html
what is the code for login page in html  Hi, I am total beginner in HTML coding. I want to make a login page in HTML to understand the form coding. I think login page is goot topic to start and learn. what is the code for login
what is the code for login page in html
what is the code for login page in html  Hi, I am total beginner in HTML coding. I want to make a login page in HTML to understand the form coding. I think login page is goot topic to start and learn. what is the code for login
provide code - Swing AWT
provide code  Dear frnds please provide code for two player CHESS GAME.....using swings,awt concepts   Hi friend, import java.awt..../java/swing/ Thanks
need code for login in asp.net with c#
need code for login in asp.net with c#  hai iam trying to develop a project in asp.net with c#,so i need a code for login page using which admin and other users can log in.plz help me, thanks in advance
Swing error in code
Swing error in code  import java.rmi.*; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; public class SClientsr extends JFrame { TextField t1=new TextField(20); Label rs
Java Swing code for zoom in and out
Java Swing code for zoom in and out  hi.......... I require a code in java swing for image zoom in and zoom out can u tell me how it can be done or what is the code plz help
source code - Swing AWT
source code  source code for a program to shutdown, restart, log off the pc after clicking jbutton on jpanel or a jframe by user. thanks in advance
java code - Swing AWT
to open the lock  Hi Friend, Try the following code: class
java code - Swing AWT
java code  Hello .anyone can plz tell me code for this .First create a button wen it is clicked its enters into another window asking for Name .After...   Hi Friend, Try the following code: import java.io.*; import
java code - Swing AWT
java code  i want to open a new dialog box after clicking "upload" button, it should have a text field, browse button to browse the file from directory  Hi Friend, Try the following code: 1)OpenDialog.java import
Java Code - Swing AWT
Java Code  How to Display a Save Dialog Box using JFileChooser and Save the loaded Image from Panel in any Location.  Hi Friend, Try the following code: import java.io.*; import java.awt.*; import java.util.
problem in swing program for opening two windows with same login credentials
problem in swing program for opening two windows with same login credentials  I Face two problems while writing the code in swing program 1.i developed one application using swings that has username,password when i login
put image on form creating in swing-swing code - Swing AWT
put image on form creating in swing-swing code  i want to display image on swing panel and get the image co ordinate by mouse clicking.and also zoom the image at particular area of image. please give solution on my email id
program code for login page in struts by using eclipse
program code for login page in struts by using eclipse  I want program code for login page in struts by using eclipse
java code for registration and login pages, mysql as a bankend.
java code for registration and login pages, mysql as a bankend.  please send me the java code for registration and login pages and to store the data in mysql
Java swing code - Java Beginners
Java swing code  How to set a font for a particular cell in JTable... in Swing. We have a huge amount of good examples on JTable here. http://www.roseindia.net/java/example/java/swing I hope this would be helpful to you
Java swing code - Java Beginners
Java swing code  How to validate input data entered into the swing applications in java?   Hi Friend, Try the following code: import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.util.
Swing login form example
Swing login form example In this example we have described swing login form. We have created one text field "textField" and one jPasswordField and we have set..._TO_REPLACE_2 Download Source Code
Need source code - Swing AWT
Need source code  Hai, In java swing, How can upload and retrieve the images from the mysql database?   Hi Friend, To upload and insert image in database, try the following code: import java.sql.*; import
jsp code for storing login and logout time to an account
jsp code for storing login and logout time to an account  I need simple jsp code for extracting and storing login and logout time in a database table..plz someone help me...   Please visit the following link: http
Causing Deadlocks in Swing Code
Causing Deadlocks in Swing At First Consider the Deadlocks A deadlock... that resources. It is a common problem in multithreading. Consider the Sample code... and by adding  the new DesktopPain to the Content Pain it starts the Swing Thread
Need source code - Swing AWT
Need source code  Hai, I need a source code for developing the project, title is "Face Recognition" and the backend as My-sql.... Thanks & Regards
game programming code - Swing AWT
game programming code  write a snake program using swings with step by step explanation?. please send me this source code to my mail id with step by step explanation
Need source code - Swing AWT
Need source code  Hai, I need a idea and code for developing the project "Face Recognition" with the backend as My-sql.... Thanks & Regards
AWT code for popUpmenu - Swing AWT
AWT code for popUpmenu  Respected Sir/Madam, I am writing a program in JAVA/AWT.My requirement is, a Form consists of a "TextBox" and a "Button... the code. ThanQ.   import java.awt.BorderLayout; import
Need source code - Swing AWT
Need source code  Hai friends, How can I, view all the datas from the mysql database table in the jframe........  Hi Friend, Try the following code: import java.awt.*; import java.sql.*; import
getting error in your login form code
getting error in your login form code  i tried your code for login form but i am getting an error.the error is undefined index userid and password.the code is $fuser=$POST["userid"];. how to solve this problem please help me
login dao file for referece (source code for reference)
login dao file for referece (source code for reference)  <!DOCTYPE...;body id="login-bg"> <!-- Start: login-holder --> <div id="login-holder"> <!-- start logo --> <div id="logo-login">
Display Logo on login form using swing
Display Logo on login form using swing In this tutorial, you will learn how to display a logo in login form using swing components. Here is an example where... a logo for this login form, we have used ImageIcon class that accepts the image
HTML Login Page Code
HTML Login Page Code Here is an example of html login page code. In this example, we have displayed one text field, Password, Reset button and Login button... JavaScript validation in Login page. We have set username and password value
login
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... to check the user name and password from the data base.. please help me for the code
login
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... to check the user name and password from the data base.. please help me for the code
login
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... to check the user name and password from the data base.. please help me for the code
login
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... to check the user name and password from the data base.. please help me for the code
login
login  sample java awt/swing code to make loginpage invisible after loggedinto next page   Hi Friend, Try the following code: 1... java.awt.event.*; class Login { JButton SUBMIT; JLabel label1,label2; final

Ads