Aplikasi Nilai Beserta Login
Berikut adalah langkah-langkah untuk membuat Aplikasi Nilai Beserta Login menggunakan Sun Java (TM) Wireless Toolkit 2.5.2.
-
Pertama pastikan komputer sudah terinstal Java JDK dan Sun Java
(TM) Wireless Toolkit 2.5.2 lalu ketikkan code source di TextPad dan
simpan dengan nama coba.java. import javax.microedition.midlet.MIDlet;import javax.microedition.lcdui.*;public class coba 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 coba() {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("byen") && password.equals("12345")) {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);}}}
- Setelah itu pada Sun Java (TM) Wireless Toolkit 2.5.2, pilih Open Project dan buka project coba, lalu Build dan Run.
- Selanjutnya adalah membuat Package. Untuk menjalankan aplikasi ini di handphone kita harus membuat file .jad , file .jad ini nantinya akan kita pindahkan ke handphone dan kita instal di handphone.Langkah-langkah pembuatan file .jad adalah sebagai berikut:
- pilih Project
- pilih Package
- pilih Create Package
- Maka file .jad akan tercipta, dan file tersebut disimpan di dalam direktori bin.
- Pindahkan file yang ada di dalam direktori bin ke handphone.
0 komentar:
Posting Komentar