program code about log in information using java JFrame

Reply

Join Date: Mar 2008
Posts: 2
Reputation: kim2_0016 is an unknown quantity at this point 
Solved Threads: 0
kim2_0016 kim2_0016 is offline Offline
Newbie Poster

program code about log in information using java JFrame

 
0
  #1
Mar 3rd, 2008
ei can u please help me to do a program that accepts username and passaword using java JFrame...
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,658
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 224
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is online now Online
Posting Virtuoso

Re: program code about log in information using java JFrame

 
0
  #2
Mar 3rd, 2008
Any beginner's java book has examples on how to create gui using javax.swing.If you don't have already such a book search the internet for tutorials. And check the java API for the following classes:
JFrame, JPanel, JTextField, JPasswordField, JButton, JLabel
And the interface ActionListener
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 10
Reputation: ahilan_23 is an unknown quantity at this point 
Solved Threads: 1
ahilan_23's Avatar
ahilan_23 ahilan_23 is offline Offline
Newbie Poster

Re: program code about log in information using java JFrame

 
0
  #3
Mar 4th, 2008
Sample Code for Login Using JFrame with MySql Server Database as Back End
Further Discussion IM ahilansoftware@gmail.com,ahilan_23@yahoo.co.in

import java.awt.*;
import java.awt.event.*;
import java.io.FileOutputStream;
import java.net.URL;
import java.net.URLConnection;
import javax.swing.*;
import java.sql.*;
import java.io.*;

/**
* Summary description for UserVallidation
*
*/
public class UserVallidation extends JFrame {
// Variables declaration
private JLabel jLabel1;
private JLabel jLabel2;
private JTextField jTextField1;
private JPasswordField jPasswordField1;
private JButton jButton1;
private JButton jButton2;
private JPanel contentPane;


Boolean loop = false;
// End of variables declaration


public UserVallidation() {
super();
initializeComponent();
//
// TODO: Add any constructor code after initializeComponent call
//
this.setVisible(true);
}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always regenerated
* by the Windows Form Designer. Otherwise, retrieving design might not work properly.
* Tip: If you must revise this method, please backup this GUI file for JFrameBuilder
* to retrieve your design properly in future, before revising this method.
*/
private void initializeComponent() {
jLabel1 = new JLabel();
jLabel2 = new JLabel();
jTextField1 = new JTextField();
jPasswordField1 = new JPasswordField();
jButton1 = new JButton();
jButton2 = new JButton();
contentPane = (JPanel)this.getContentPane();

//
// jLabel1
//
jLabel1.setText("EK UserName");
//
// jLabel2
//
jLabel2.setText("EK Password");
//
// jTextField1
jTextField1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jTextField1_actionPerformed(e);
}

});
//
// jPasswordField1
//
jPasswordField1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jPasswordField1_actionPerformed(e);
}

});
//
// jButton1
//
jButton1.setText("OK");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}

});
//
// jButton2
//
jButton2.setText("Cancel");
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}

});
//check boxes


//
// contentPane
//
contentPane.setLayout(null);
addComponent(contentPane, jLabel1, 10,20,91,18);
addComponent(contentPane, jLabel2, 10,70,77,18);
addComponent(contentPane, jTextField1, 100,20,100,22);
addComponent(contentPane, jPasswordField1, 100,70,100,22);
addComponent(contentPane, jButton1, 50,100,83,28);
addComponent(contentPane, jButton2, 170,100,83,28);

// UserVallidation
//
this.setTitle("EK User Verification");
this.setLocation(new Point(390, 300));
this.setSize(new Dimension(290, 200));
jPasswordField1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
jPasswordField1KeyPressed(evt);
}
/* public void keyTyped(java.awt.event.KeyEvent evt) {
txt_useremailKeyTyped(evt);
}*/
});
}

/** Add Component Without a Layout Manager (Absolute Positioning) */
private void addComponent(Container container,Component c,int x,int y,int width,int height) {
c.setBounds(x,y,width,height);
container.add(c);
}



//
// TODO: Add any appropriate code in the following Event Handling Methods
//
private void jTextField1_actionPerformed(ActionEvent e) {
System.out.println("\njTextField1_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here

}

private void jPasswordField1_actionPerformed(ActionEvent e) {
System.out.println("\njPasswordField1_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here

}

private void jButton1_actionPerformed(ActionEvent e) {

login();
System.out.println("\njButton1_actionPerformed(ActionEvent e) called.");
}
//action listener
private void jPasswordField1KeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
if(evt.getKeyCode() == 10) {
login();
}
}


public void login() {
String username=null;
String password=null;
String dburl=null;
String dburl1=null;
String dburl2=null;
DataInputStream dis=null;
username = new String(jTextField1.getText());
password = new String(jPasswordField1.getPassword());
if((username.equals(""))&&(password.equals(""))) {
JOptionPane.showMessageDialog(this,"Enter the UserName and Password","User Verification",1);
new UserVallidation();
} else if((username.equals(""))) {
JOptionPane.showMessageDialog(this,"Enter the UserName ","User Verification",1);
new UserVallidation();
} else if((password.equals(""))) {
JOptionPane.showMessageDialog(this,"Enter the Password ","User Verification",1);
new UserVallidation();
} else {
try {
dburl = "jdbc:mysql://127.0.0.1:3306/"
dburl1 = "root";
dburl2="admin";
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(dburl,dburl1,dburl2);
Statement stat=con.createStatement();
System.out.println("connection opened");
PreparedStatement pstmt1=null;
ResultSet rs=null;
do{
loop = false;
username = new String(jTextField1.getText());
password = new String(jPasswordField1.getPassword());
pstmt1=con.prepareStatement("select username,password from TBLEK_REGISTRATION where username=? and password=?");
pstmt1.setString(1,username);
pstmt1.setString(2,password);
rs=pstmt1.executeQuery();
if(!rs.next() && rs.getRow() == 0) {
JOptionPane.showMessageDialog(this,"Login Failed. Please try again!");
jTextField1.setText("");
jPasswordField1.setText("");
loop = true;
new UserVallidation();
break;
}else {

username = rs.getString("username");
password=rs.getString("password");
this.setVisible(false);

}
}while (loop);

}catch(Exception Ex) {

System.out.println("Exception arises"+Ex);
}

}
this.setEnabled(false);
this.setVisible(false);
}
private void jButton2_actionPerformed(ActionEvent e) {
System.exit(1);
System.out.println("\njButton2_actionPerformed(ActionEvent e) called.");

}


}
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 164
Reputation: orko is an unknown quantity at this point 
Solved Threads: 10
orko orko is offline Offline
Junior Poster

Re: program code about log in information using java JFrame

 
0
  #4
Mar 4th, 2008
It is not encouraged to post such straight forward solution here. This forum definitely discourage the "copy-paste" manner.
A Perfect World
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC