Posted in IT

Project LoginSample

import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;

public class LoginSample extends MIDlet implements CommandListener{
private Display display;
private TextField userName,password;
public Form form;
private Command login,cancel;
private Image img, imge, img2;

public LoginSample() {
form = new Form(“Sign in”);
userName = new TextField(“LoginID:”, “”, 30, TextField.ANY);
password = new TextField(“Password:”, “”, 30, TextField.PASSWORD);
cancel = new Command(“Cancel”, Command.CANCEL, 2);
login = new Command(“Login”, Command.OK, 2);
try{
img = Image.createImage(“/logo.png”);
imge = Image.createImage(“/front_left1_bad.png”);
img2 = Image.createImage(“/Congratulations-1.png”);
}catch(Exception e){
System.out.println(e.getMessage());
}
}

public void startApp() {
display = Display.getDisplay(this);
try{form.append(img);}catch(Exception e){}
form.append(userName);
form.append(password);
form.addCommand(cancel);
form.addCommand(login);
form.setCommandListener(this);
display.setCurrent(form);
}

public void pauseApp() {}

public void destroyApp(boolean unconditional) {
notifyDestroyed();
}

public void validateUser(String name, String password) {
if (name.equals(“hilwa”) && password.equals(“hilwa”)) {
showMsg();
} else {
tryAgain();
}
}

public void showMsg() {
Alert success = new Alert(“Login Successfully”, “Your Login Process is completed!”, img2, AlertType.INFO);
success.setImage(img2);
userName.setString(“”);
password.setString(“”);
display.setCurrent(success, form);
}

public void tryAgain() {
Alert error = new Alert(“Login Incorrect”, “Please try again”, imge, AlertType.ERROR);
error.setTimeout(900);
error.setImage(imge);
userName.setString(“”);
password.setString(“”);
display.setCurrent(error, form);
}

public void commandAction(Command c, Displayable d) {
String label = c.getLabel();
if(label.equals(“Cancel”)) {
destroyApp(true);
} else if(label.equals(“Login”)) {
validateUser(userName.getString(), password.getString());
}
}
}

 

Nah, ini hasilnya, jree…ng

 

 

 

 

 

 

 

 

 

 

Kalo loginnya bener, ini hasilnya:

 

Advertisements

Author:

Siapa itu hilwa? Oh, itu pertanyaan yang sangat bagus! Hilwa itu adalah nickname dari seseorang yang bernama Wirda Hilwa, Tapi Wirda Hilwa itu masih punya nickname yang lain, yaitu wirda, dan iwa. Dari beberapa nickname itu Wirda Hilwa paling suka dipanggil Hilwa, karena arti dari hilwa itu adalah... hmm..., ga jadi deh, rahasia :P . [Sekarang serius mode:on ] Singkatnya aja, hilwa itu adalah seseorang yang hobi baca blog2 orang utk diambil manfaat & pelajaran dari blog tsb. Lalu terinspirasi pula utk membuat blog sendiri, utk berbagi yang bisa dibagi kpd orang lain. Semoga blog ini dapat bermanfaat buat yang baca. Amiin.

2 thoughts on “Project LoginSample

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s