Sedikit berbagi informasi tentang pemrograman java khususnya J2ME, ini source code untuk aplikasi Login untuk J2ME.
Semoge bermanfaat!!
:)
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class FormLogin extends MIDlet implements CommandListener, ItemCommandListener {
Display display;
Form textForm;
Command exitCommand = new Command("Exit", Command.EXIT, 1);
Command exitToForm = new Command("Back", Command.EXIT, 1);
Command ok = new Command("Set", Command.ITEM, 0);
Ticker ticker = new Ticker("Silahkan Login di Sini!!");
TextField user,passwd;
StringItem button;
Image imge, img2;
public FormLogin(){
display = Display.getDisplay(this);
textForm = new Form("Masukan Nama dan Password :");
textForm.addCommand(exitCommand);
textForm.setCommandListener(this);
user = new TextField("USERNAME", "", 64, TextField.ANY);
passwd = new TextField("PASSWORD", "", 64, TextField.PASSWORD);
button = new StringItem("", "Login", Item.BUTTON);
button.setDefaultCommand(ok);
button.setItemCommandListener(this);
textForm.append(user);
textForm.append(passwd);
textForm.append(button);
textForm.setTicker(ticker);
try{
imge = Image.createImage("/gagal.png");
img2 = Image.createImage("/sukses.png");
}catch(Exception e){
System.out.println(e.getMessage());
}
}
public void startApp() {
display.setCurrent(textForm);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable d){
if (c == exitCommand){
destroyApp(true);
notifyDestroyed();
}else if (c == exitToForm){
display.setCurrent(textForm);
}
}
public void commandAction(Command c, Item item){
if(c==ok || button == item){
if(user.getString().equals("") || passwd.getString().equals("")) {
Alert pesan1 = new Alert ("Warning !!!!","Username dan Password belum dimasukkan!!!",null,AlertType.WARNING);
pesan1.setImage(imge);
pesan1.setTimeout(2000);
display.setCurrent(pesan1);
}else if(user.getString().equals("hardi")) {
if (passwd.getString().equals("251091")) {
Alert pesan = new Alert ("Informasi !!!!","Login Anda Berhasil",null,AlertType.INFO);
pesan.setImage(img2);
pesan.setTimeout(Alert.FOREVER);
pesan.addCommand(exitToForm);
pesan.setCommandListener(this);
user.setString("");
passwd.setString("");
display.setCurrent(pesan);
}else{
Alert pesan2 = new Alert ("Informasi !!!!","Password yang Anda masukkan Salah, Silahkan coba lagi!!",null,AlertType.INFO);
pesan2.setTimeout(2000);
pesan2.setImage(imge);
display.setCurrent(pesan2);
}
}else{
Alert pesan3 = new Alert ("Informasi !!!!","Username yang Anda masukkan Salah, Silahkan Coba lagi!!",null,AlertType.INFO);
pesan3.setTimeout(2000);
pesan3.setImage(imge);
display.setCurrent(pesan3);
}
}
}
}
0 komentar:
Posting Komentar