[trick] Login dan Logout Dengan Java Desktop tanpa Database

1. Form Login

import javax.swing.JOptionPane;
public class frm1 extends javax.swing.JFrame {
//nama class frm atau form login
public frm1() {
initComponents();
setLocation(200,200); //ukuran frame
}
@SuppressWarnings("unchecked")
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

String name=""; // variable nama
String password="123456"; variable password

name=jTextField1.getText(); // name dari textfield
if(password.equals(jPasswordField1.getText())){
frm2 fl =new frm2(name); //munculkan frame 2
fl.setVisible(true); // nilai frame true
this.dispose();
}else{
JOptionPane.showMessageDialog(rootPane,"Login Gagal"); // jika nama dan password salah

}

}

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {

}

public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new frm1().setVisible(true);
}
});
}
private javax.swing.JButton jButton1; //name button
private javax.swing.JPasswordField jPasswordField1; // name field password
private javax.swing.JTextField jTextField1; // name field textfield
}

2.Proses Login

package frame1;
public class frm2 extends javax.swing.JFrame {
String para ;

public frm2() {
initComponents();
}

public frm2(String name) {
initComponents();
para = name;
jLabel1.setText(name);
setLocation(200,200);
}
@SuppressWarnings("unchecked")

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new frm2().setVisible(true);
}
});
}

private javax.swing.JLabel jLabel1;

}

 

Leave a comment

1 Comment

  1. Reblogged this on Dinesh Ram Kali..

    Reply

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: