Mariesa Rahmawati’s Weblog

Menuju hari esok yang lebih baik

Source code java untuk Login

/*
* login.java
*
* Created on December 12, 2005, 8:15 PM
*/

package onlinepayment;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import javax.sql.*;
import oracle.sql.*;

public class login extends JFrame{
private JButton BtnLogin;
private JLabel LblUser,LblPassword;
private JPasswordField FieldPassword;
private JTextField FieldUser;
private Container c;
// public tab_panel tp;
private String strUserName = “”;
private String strPwd = “”;
private String strService = “”;

/** Creates new form login */
public login() {
init();
}

private void init() {
c=getContentPane();
setTitle(“LOGIN DATABASE”);

c.setLayout(null);
LblUser = new JLabel(“UserName”);
LblUser.setBounds(100, 50, 60, 20);
c.add(LblUser);
LblPassword = new JLabel(“Password”);
LblPassword.setBounds(100, 80, 60, 20);
c.add(LblPassword);
FieldUser = new JTextField();
FieldUser.setBounds(180, 50, 110, 21);
c.add(FieldUser);
FieldPassword = new JPasswordField();
FieldPassword.setBounds(180, 80, 110, 23);
c.add(FieldPassword);
BtnLogin = new JButton(“LOGIN”);
BtnLogin.setBounds(200, 110, 80, 25);
c.add(BtnLogin);
BtnLogin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnLoginConect(evt);
}
});

java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-410)/2, (screenSize.height-209)/2, 410, 209);

addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
FieldPassword.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});

}

/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);

}

public static void main(String args[]) {
new login().show();
}
public void BtnLoginConect(java.awt.event.ActionEvent evt) {
try {
strUserName = FieldUser.getText();
strPwd = String.valueOf(FieldPassword.getPassword());

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

Connection con = DriverManager.getConnection(“jdbc:oracle:thin:@informatika:1521:orcl9i”,strUserName, strPwd);
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(“Select ‘Connected’ from dual”);
rs.next();
String s = rs.getString(1);
st.close();
con.close();
// tp=new tab_panel(strUserName,strPwd);
this.dispose();
}
catch(SQLException e) {
String pesanError = “”;

if(e.getErrorCode() == 17433) {
pesanError = “Field Harus Diisi / null.”;
}
else if(e.getErrorCode() == 1017) {
pesanError = “Cek kembali username Atau Password Anda.”;
}
else if(e.getErrorCode() == 17002) {
pesanError = “Service tidak bisa diakses.”;
}
JOptionPane.showMessageDialog(null, pesanError, “Login Error”, JOptionPane.ERROR_MESSAGE);
}

}
}

June 25, 2008 - Posted by | Pemrograman

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: