login screen

Ads
 

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

Ads









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
Screen Capture
Screen Capture  How to capture the screen using jsps and servlets
Advertisements
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
Screen shot
Screen shot  webpage screenshot source code
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
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
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 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
Caputuring screen shot
Caputuring screen shot  How to to capture screen shot for a computer on internet
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
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
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  code for login page
login page
login page  How to login as different user in php
Login page
Login page  how to create Login page in java
login-logout
login-logout  how to do login and logout using session in php

Ads