ROGRAM APLIKASI NILAI
1. buat project baru dengan nama nilai pada wireless toolkit
2. ketik program nilai menggunakan notepad++ atau textpad
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class nilai extends MIDlet implements CommandListener{
private Display display;
private TextField userName,password;
public Form form;
private Command login,cancel;
private Image img, imge, img2;
Command cmdExit,cmdBack,cmdHitung;
Display dis;
Form frmInput,frmOutput;
TextField tfMakul,tfNilai;
StringItem siMakul,siSKS,siNilai,siGrade,siBobot;
ChoiceGroup cg1;
public nilai() {
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("/gagal.png");
img2 = Image.createImage("/sukses.png");
}catch(Exception e){
System.out.println(e.getMessage());
}
cmdExit = new Command("Keluar",Command.EXIT,0);
cmdBack = new Command("OK",Command.SCREEN,0);
cmdHitung = new Command("Proses",Command.SCREEN,0);
cg1=new ChoiceGroup("SKS",Choice.EXCLUSIVE);
cg1.append("2 SKS",null);
cg1.append("4 SKS",null);
cg1.append("6 SKS",null);
frmInput=new Form("Form Input");
tfMakul = new TextField("Mata Kuliah","",30,TextField.ANY);
tfNilai = new TextField("Nilai","",30,TextField.NUMERIC);
frmInput.append(tfMakul);
frmInput.append(cg1);
frmInput.append(tfNilai);
frmInput.addCommand(cmdExit);
frmInput.addCommand(cmdHitung);
frmInput.setCommandListener(this);
frmOutput=new Form("Form Output");
siMakul=new StringItem("Mata Kuliah","");
siSKS=new StringItem("SKS","");
siNilai=new StringItem("Nilai","");
siGrade=new StringItem("Grade","");
siBobot=new StringItem("Bobot Nilai",null);
frmOutput.append(siMakul);
frmOutput.append(siSKS);
frmOutput.append(siNilai);
frmOutput.append(siGrade);
frmOutput.append(siBobot);
frmOutput.addCommand(cmdBack);
frmOutput.setCommandListener(this);
}
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("kakcik") && password.equals("211")) {
showMsg();
} else {
tryAgain();
}
}
public void showMsg() {
dis = Display.getDisplay(this);
dis.setCurrent(frmInput);
}
public void tryAgain() {
Alert error = new Alert("Login salah", "coba lagi", 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());
}
if(c==cmdBack){
dis.setCurrent(frmInput);
}else if(c==cmdHitung){
int nilai,nilaigrade,bobotnilai,sks;
siMakul.setText(tfMakul.getString());
if(cg1.isSelected(0)){
siSKS.setText("2 SKS");
sks=2;
}else if(cg1.isSelected(1)){
siSKS.setText("4 SKS");
sks=4;
}else{
siSKS.setText("6 SKS");
sks=6;
}
siNilai.setText(tfNilai.getString());
nilai=Integer.parseInt(tfNilai.getString());
if(nilai<=49){
siGrade.setText("E");
nilaigrade=0;
}else if(nilai<=59){
siGrade.setText("D");
nilaigrade=1;
}else if(nilai<=74){
siGrade.setText("C");
nilaigrade=2;
}else if(nilai<=80){
siGrade.setText("B");
nilaigrade=3;
}else{
siGrade.setText("A");
nilaigrade=4;
}
bobotnilai=sks*nilaigrade;
siBobot.setText(Integer.toString(bobotnilai));
dis.setCurrent(frmOutput);
}else if(c==cmdExit){
destroyApp(false);
notifyDestroyed();
}else{
dis.setCurrent(frmInput);
}
}
}
3. setelah selesai build program tersebut lalu pilih run
Tidak ada komentar:
Posting Komentar