Membuat Formlogin
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class FormLogin extends JFrame implements ActionListener {
private JLabel label1, label2;
private JTextField txtUser;
private JPasswordField pwdPass;
private JButton btnLogin, btnExit;
public FormLogin(){
super ("FormLogin");
Container container = getContentPane();
container.setLayout(new FlowLayout());
label1 = new JLabel ("Username : ");
label2 = new JLabel ("Password : ");
txtUser = new JTextField(20);
txtUser.setToolTipText("Input Username");
pwdPass = new JPasswordField(20);
btnLogin = new JButton ("Login");
btnLogin.addActionListener(this);
btnExit = new JButton ("Exit");
btnExit.addActionListener(this);
container.add(label1);
container.add(txtUser);
container.add(label2);
container.add(pwdPass);
container.add(btnLogin);
container.add(btnExit);
setSize (00,200);
setVisible (true);
}
public static void main(String[] args) {
FormLogin test = new FormLogin();
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private String user = "",pass = "";
public void actionPerformed (ActionEvent e){
if (e.getSource() == btnLogin){
user = txtUser.getText();
pass = pwdPass.getText();
if (user.equals("scada") && pass.equals("scada77")){
JOptionPane.showMessageDialog(null, "Terima kasih anda telah berhasil login ");
System.exit(0);
}else{
JOptionPane.showMessageDialog(null, "Username and password salah");
txtUser.setText("");
pwdPass.setText("");
txtUser.requestFocus(true);
}
}else if (e.getSource() == btnExit){
JOptionPane.showMessageDialog(null, "Anda sudah keluar");
System.exit(0);
}
}
}
import java.awt.event.*;
import javax.swing.*;
public class FormLogin extends JFrame implements ActionListener {
private JLabel label1, label2;
private JTextField txtUser;
private JPasswordField pwdPass;
private JButton btnLogin, btnExit;
public FormLogin(){
super ("FormLogin");
Container container = getContentPane();
container.setLayout(new FlowLayout());
label1 = new JLabel ("Username : ");
label2 = new JLabel ("Password : ");
txtUser = new JTextField(20);
txtUser.setToolTipText("Input Username");
pwdPass = new JPasswordField(20);
btnLogin = new JButton ("Login");
btnLogin.addActionListener(this);
btnExit = new JButton ("Exit");
btnExit.addActionListener(this);
container.add(label1);
container.add(txtUser);
container.add(label2);
container.add(pwdPass);
container.add(btnLogin);
container.add(btnExit);
setSize (00,200);
setVisible (true);
}
public static void main(String[] args) {
FormLogin test = new FormLogin();
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private String user = "",pass = "";
public void actionPerformed (ActionEvent e){
if (e.getSource() == btnLogin){
user = txtUser.getText();
pass = pwdPass.getText();
if (user.equals("scada") && pass.equals("scada77")){
JOptionPane.showMessageDialog(null, "Terima kasih anda telah berhasil login ");
System.exit(0);
}else{
JOptionPane.showMessageDialog(null, "Username and password salah");
txtUser.setText("");
pwdPass.setText("");
txtUser.requestFocus(true);
}
}else if (e.getSource() == btnExit){
JOptionPane.showMessageDialog(null, "Anda sudah keluar");
System.exit(0);
}
}
}
Komentar
Posting Komentar