Janet
login screen
1 Answer(s)      2 years and 8 months ago
Posted in : Java Beginners

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 Pages:
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
Login Screen of Application
Login Screen of Application       Login Screen our web application allows the user... to logged on the system.  Login Screen: Field Description: Login Id
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
login
login  login page display an error showing failure to login even when the correct information is entered
LOGIN PROBLEM - JDBC
LOGIN PROBLEM   sir iam harikrishna studying B.Tech Fourth year sir i'm designing one website in that one i have to give facility as login id... in the Database to store user details - Put some Signup screen and ask user
Screen Capture
Screen Capture  How to capture the screen using jsps and servlets
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 shot
Screen shot  webpage screenshot source code
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 Here 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">
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
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  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
Struts 2 Login Application
Struts 2 Login Application       Developing Struts 2 Login Application In this section we are going to develop login application based on Struts 2 Framework. Our current login application
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 Coordinates
Java NotesScreen Coordinates Every computer monitor screen is made of pixels. Each pixel is a small spot on the screen. There are approximately 3 pixels... on the screen. A typical screen might be 800 pixels wide and 640 pixels high
Creating Midlet Application For Login in J2ME
Creating MIDlet Application For Login in J2ME  ... application for user login . All MIDlet applications for the MIDP ( Mobile Information... Gauge Graphics Image ImageItem Item List Screen StringItem TextBox
Login/Logout With Session
;Logout" then again login page is displayed on the screen. Here is the code...Login/Logout With Session       In this section, we are going to develop a login/logout application with session
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
login dao file for referece (source code for reference)
login dao file for referece (source code for reference)  <!DOCTYPE.../screen.css" type="text/css" media="screen" title="default" /> <!-- jquery...;body id="login-bg"> <!-- Start: login-holder --> <div id="login
Screen Scraping - Ajax
Screen Scraping  How i can do the screen scraping using java and ajax
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
How to use filter to redirect to login page after session timeout.
How to use filter to redirect to login page after session timeout.  ... session timeout . means if screen is inactive for a particular period of time then automatically it should redirect to login page from where user has
How to use filter to redirect to login page after session timeout.
How to use filter to redirect to login page after session timeout.  ... session timeout . means if screen is inactive for a particular period of time then automatically it should redirect to login page from where user has
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
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!   Finally find it on the apple website... The iPad display has a screen resolution
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
How to use filter to redirect to login page after session timeout
How to use filter to redirect to login page after session timeout  ... timeout . means if screen is inactive for a particular period of time then automatically it should redirect to login page from where user has to login again
login page
login page  code for login page
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
Running and Testing Struts 2 Login application
Running and Testing Struts 2 Login application       Running Struts 2 Login Example In this section we will run...://localhost:8080/struts2tutorial/. Your browser should show the following screen
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 page
Login page  how to create Login page in java
splash screen time delay iphone
splash screen time delay iphone  How can i delay the splash screen?   How to delay splash screen in iPhone/iPad/ Objective C Splash scree is the very first screen that run while application launch. By default
virtual on screen keyboar - Swing AWT
virtual on screen keyboar  sir i need shift key operation code in my project program of virtual keyboard can uplz send
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.