Share on Google+Share on Google+

Janet
login screen
1 Answer(s)      6 years and 7 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

Ads

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: Field Description: Login Id
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 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
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
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  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
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
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
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
Caputuring screen shot
Caputuring screen shot  How to to capture screen shot for a computer on internet
Screen Flickers - Framework
Screen Flickers  One of my screen flickers. Is that is beacuse of less memory
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
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
Tutorials   
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code

Ads

 
Advertisement null

Ads