Search for Knowledge
“A mistake is a signal that it is time to learn something new, something you didn’t know before.”

Login java

Login Java

import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;

public class login extends Frame{
Label tInfo;
TextField f1, f2;
Button b;

publicc static void main (String[] args) {
login apl = new login();
 }

public login() {
super(“Login”);
setSize(300, 120);

Label t1 = new label (“Username:”);
f1 = new TextField(“”,10);
Label t2 = new label (“Password:”);
f2 = new TextField(“”,10);
f2.setEchoChar(‘*’);

b = new Button(“Login”);
tInfo = new label();

Panel p1 new Panel();
p1.setLayout(new GridLayout(2,2));
p1.add(t1);
p1.add(f1);
p1.add(t2);
p1.add(f2);

panel p2 = new panel ();
p2.setLayout(new FlowLayout());

p2.add(b);
p2.add(tInfo);

add(“North”, p1);
add(“South”, p2);

b.addActionListener (new login.PenangananTombol()));

show();
}

class PenangananTombol implements ActionListener {
public void actionPerformed(ActionEvent e) {
String s= e.Equals(“Login”) ) {
String user = f1.getText();
String password=f2.getText();
if (user.compareTo(“Wyka”) = 0 && password.compareTo(“nova”)==0)
JOptionPane.showMessageDialog(null, “Login Sukses”, “Informasi”, JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null, “Username dan Password salah”, “Peringatan”, JOptionPane.INFORMATION_MESSAGE);
}
}
}
}

Untuk mengecek kesalahan menggunakan perintah javac login.java pada command prompt

untuk menjalankan program java menggunakan perintah java login pada perintah command prompt