login screen

login screen

how can code a login screen please send me the code
with two entries Username and Password and validate it please
View Answers

September 27, 2010 at 2:34 PM

Hi Friend,

Try the following code:

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

class LoginDemo{
JButton SUBMIT;
JFrame f;
JLabel label1,label2;
final JTextField text1;
final JPasswordField text2;
LoginDemo(){
f=new JFrame();
f.getContentPane().setLayout(null);
label1 = new JLabel();
label1.setText("UserName:");
label1.setBounds(400,50,100,20);
text1 = new JTextField(25);
text1.setBounds(500,50,100,20);
label2 = new JLabel();
label2.setText("Password:");
label2.setBounds(400,80,100,20);
text2 = new JPasswordField(25);
text2.setBounds(500,80,100,20);
SUBMIT=new JButton("Login");
SUBMIT.setBounds(500,110,100,20);

f.add(label1);
f.add(text1);
f.add(label2);
f.add(text2);
f.add(SUBMIT);
f.setSize(1024,768);
f.setVisible(true);
SUBMIT.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String value1=text1.getText();
String value2=text2.getText();
String user1="";
String pass1="";
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql";, "root", "root");
Statement st = con.createStatement();
ResultSet res = st.executeQuery("SELECT * FROM login where username='"+value1+"' and password='"+value2+"'");
while (res.next()) {
user1 = res.getString("username");
pass1 = res.getString("password");
}
if(!value1.equals(user1) && !value2.equals(pass1)) {
JOptionPane.showMessageDialog(null,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE);
text1.setText("");
text2.setText("");
}
else if(value1.equals("")){
JOptionPane.showMessageDialog(null,"Please Enter Username");
}
else if(value2.equals("")){
JOptionPane.showMessageDialog(null,"Please Enter Password");
}
else if(value2.length()<6){
JOptionPane.showMessageDialog(null,"Password should consist atleast 6 characters!");
}

else{

JOptionPane.showMessageDialog(null,"Login Successful");
}

}
catch(Exception e){
System.out.println(e.getMessage());
}
}
});
}
public static void main(String arg[]) {
LoginDemo frame=new LoginDemo();
}
}

Thanks









Related Tutorials/Questions & Answers:
iphone login screen
 Mode       The   App   will   begin   with   the   Login   Screen,   The   screen   should   be   having   same   functionality  as  any  website...iphone login screen  Hi i need solution of below question if any one
login screen - Java Beginners
login screen  how can code a login screen please send me the code...(500,80,100,20); SUBMIT=new JButton("Login"); SUBMIT.setBounds... * FROM login where username='"+value1+"' and password='"+value2
Advertisements
Login Screen of Application
Login Screen of Application       Login Screen our web application allows the user... to logged on the system.  Login Screen: ADS_TO_REPLACE_1 Field Description
login
login  How to create login page in jsp
login
login  How to create login page in jsp
login
login  login page display an error showing failure to login even when the correct information is entered
login
login  how to login admin and user with the same fields(name & password) in single login page while the table for admin and user is seprate in database(mysql) please provide me solution
login
login  i want to now how i can write code for form login incolude user and password in Jcreator 4.50   Hello Friend, Visit HereADS_TO_REPLACE_1 Thanks
login
java.awt.event.*; class Login { JButton SUBMIT; JLabel label1,label2; final JTextField text1,text2; Login() { final JFrame f=new JFrame("Login Form...(); ResultSet rs=st.executeQuery("select * from login where username='"+value1
login
login  how to create login page in jsp   Here is a jsp code that creates the login page and check whether the user is valid or not. 1...;tr><td></td><td><input type="submit" value="Login">
login
login  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
login
login  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
login
login  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
login
login  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
Screen Capture
Screen Capture  How to capture the screen using jsps and servlets
Screen shot
Screen shot  webpage screenshot source code
splash screen
splash screen  What is splash screen and how can i set splash screen in iphone??   hello, if you want to launch splash screen then add... splash screen will show launching time.. ADS_TO_REPLACE_1
Screen Capture
Screen Capture  Hi deepak, I am trying to take a screen shot using java script Activex object. But Iam getting Automation server cant create object exception .how can i solve
Screen flashing
Screen flashing  Hey I am trying to make my screen flash (like...; </th> <th class="login" align="center" onMouseOver... I want is that I want the screen to flash white when a link is clicked. Thanks
How to Manage Windows 8 Start screen?
user interface called the Windows Start Screen or Metro Style Interface that appears to you when you login to Windows 8. This time the start screen contains... on the programs. Let us learn, how to manage your Windows 8 Start screen. Unpin
Splash Screen in Java Swing
Splash Screen in Java Swing  I worte this code,but i'm unable to add this class code to my main class.so plz i request you to guide me how can i add this splesh screen to my main-class-login-page-screen. package Com.Demo
difference between touch screen and non touch screen
difference between touch screen and non touch screen  what is a difference between touch screen and non touch screen in J2ME (code wise
difference between touch screen and non touch screen
difference between touch screen and non touch screen  code wise ,what is a difference between touch screen and non touch screen in J2ME
Screen Flickers - Framework
Screen Flickers  One of my screen flickers. Is that is beacuse of less memory
Caputuring screen shot
Caputuring screen shot  How to to capture screen shot for a computer on internet
Screen Scraping - Ajax
Screen Scraping  How i can do the screen scraping using java and ajax
login page
login page  code for login page
ModuleNotFoundError: No module named 'screen'
ModuleNotFoundError: No module named 'screen'  Hi, My Python... 'screen' How to remove the ModuleNotFoundError: No module named 'screen'... to install padas library. You can install screen python with following command
create a named screen in linux
create a named screen in linux  Hi, I want to create a screen session with a name. I wanto to assign a name while creating screen. So, need help of your guys to tell me the command. How to create a named screen in linux
recorder screen in java
recorder screen in java  Dear friends, how can I capture the screen in real time? best regards Riccardo Susca
recorder screen in java
recorder screen in java  Dear friends, how can I capture the screen in real time? best regards Riccardo Susca
noise during print screen
noise during print screen  hi there, i have a java program which can print screen every 1 seconds... but during the print screen, the image seems will have some noise and ends up half page of the image will be black screen
iPhone Capturing Screen SDK
iPhone Capturing Screen SDK  Creating an application to capture the screen shots from iPhone. In objective c is there any class that make it enable..?   UIGraphicsBeginImageContext(CGSizeMake(480,320)); UIImage* result
Login page
Login page  how to create Login page in java
login page
login page  How to login as different user in php
login-logout
login-logout  how to do login and logout using session in php
LOGIN ERROR
LOGIN ERROR  ERROR SCRIPT: LOGIN FAILED", $_SESSION['login fail']='0',}?> Ty Team
Touch screen effect
Touch screen effect  Hello everyone, I would like to create a desktop application using java, is it possible to have touch screen effect for the desktop application? Exp: when user click next button, whole screen will move
Login authentication
Login authentication  i want d code for login authentication from mysql database on the same pc using swings
Login authentication
Login authentication  i want d code for login authentication from mysql database on the same pc using swings
ipad screen resolution pixels
ipad screen resolution pixels  Hi! Can you tell the exact size of the iPad in pixels ..including height & width. Thanks Very Much!   ... a screen resolution of .. 1024×768 pixels other details..ADS_TO_REPLACE_2
populating a screen on the same page
populating a screen on the same page  i'm making a time table in jsp. i have put button on each slot.if a person click on that slot it'll redirect... down. But now i want that onclicking slot(button) a small selection screen like
Splash Screen in Java Swing
Splash Screen in Java Swing  i wrote this code for splash screen but i'm unable to connect to my main code so i humble request you to plzz how can i connect to my main code. package Com.Demo; import javax.swing.ImageIcon
Login Page
Login Page  Can anyone tell me the steps to create a login page in myeclipse 7.0 and validating it with login database in db2 9.7 ??? Please tell me
messages to the screen without using "document.write()"
messages to the screen without using "document.write()"  To write messages to the screen without using "document.write
LOGIN PAGE
LOGIN PAGE  A java program with "login" as title,menus added, and a text field asking for firstname, lastname, and displaying current date and time
login application
login application  how to create login application ?   Hi, Please check the following tutorials: Video tutorial - JSP Login Logout Example Login Authentication using Bean and Servlet In JSP simple code to login user
Login modification
Login modification  How can I invalidate a user once he goes back to login page without signing out,I have already tried using session but it doesn't work please help
login box
login box  class file for password and conform password and how it connected to database
ModuleNotFoundError: No module named 'pelk-screen'
ModuleNotFoundError: No module named 'pelk-screen'  Hi, My Python... 'pelk-screen' How to remove the ModuleNotFoundError: No module named 'pelk-screen' error? Thanks   Hi, In your python environment

Ads