Senin, 25 Oktober 2010

Login Form

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;

/**
*
* @author Administrator
*/

class properties extends JFrame implements ActionListener{
JLabel Lusername = new JLabel("Username");
JLabel Lpassword = new JLabel("Password");
JPasswordField Ppassword = new JPasswordField(20);
JTextField Tusername = new JTextField(20);
JButton bok = new JButton("OK");
JButton bcancel = new JButton("Cancel");

public properties( String Judul ){
add(Lusername);
add(Tusername);
add(Lpassword);
add(Ppassword);
add(bok);
add(bcancel);

setVisible(true);
setSize(350, 150);
setLayout(null);
setDefaultCloseOperation(3);
setTitle(Judul);
setLayout(new FlowLayout());

bok.addActionListener(this);
bcancel.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
if(ae.getSource() == bok) {
if(Tusername.getText().equals("123090091")&&Ppassword.getText().equals("java2"))
JOptionPane.showMessageDialog(this, "Login Success\n" +
"", "message",
JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(this, "Login Failed\n" +
"Please Try Again!", "message",
JOptionPane.INFORMATION_MESSAGE);
Tusername.setText("");
Ppassword.setText("");
}
if(ae.getSource()==bcancel){
System.exit(0);
}
}
}

public class Loginform {
public static void main(String[] args) {
properties p = new properties("Login Form");
}
}

ini hasil programnya :


Jika Login gagal :

Tidak ada komentar:

Posting Komentar