Filename | Membuat Login sederhana di java |
Permission | rw-r--r-- |
Author | Artikel |
Date and Time | 09.05 |
Label | java |
Action |
:)
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
* @author ho1onk
*/
public class login2 extends MIDlet implements CommandListener {
TextField pin,user;
Form fr1,fr2;
Display d;
Image g,g2;
Command OK, back;
String pass="123";
public login2(){
pin = new TextField ("Pin Anda : ","",5,TextField.PASSWORD );
user = new TextField ("User : ","",50,TextField.ANY);
OK = new Command ("OK",Command.OK,0);
back = new Command ("Back",Command.BACK,0);
fr1 = new Form ("Menu Utama");
fr1.append(user);
fr1.append(pin);
fr1.addCommand(OK);
fr1.setCommandListener(this);
// form 2
fr2 = new Form ("Selamat Datang");
//membuat gambar
try {
g=Image.createImage("/lock.png");
g2=Image.createImage("/hn.jpg");
}catch(Exception e){e.printStackTrace();}
//fr2.append(g);
fr2.setCommandListener(this);
fr2.addCommand(back);
}
public void startApp() {
d=Display.getDisplay(this);
d.setCurrent(fr1);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command x, Displayable x1) {
if(x==back){
d.setCurrent(fr1);
}
if (x == OK){
if (pin.getString().endsWith(pass)){
String a = user.getString();
String b = pin.getString();
fr2.append("Anda berhasil login dengan \n\nUser : ");
fr2.append(a);
fr2.append("\n Pin : ");
fr2.append(b);
fr2.append("\n\n\n");
fr2.append(g);
d.setCurrent(fr2);
}
else {
fr2 = new Form ("User atau password Salah ");
//fr2.append("User atau password yang anda masukkan salah");
fr2.addCommand(back);
fr2.append(g2);
d.setCurrent(fr2);
}
}
throw new UnsupportedOperationException("Not supported yet.");
}
}
Semoga berguna =))