Senin, 07 Juli 2014

Kunci Jawaban UAS Kelas Java Semester Genap 2013-2014

Coding berikut ini adalah coding yang tidak mengandung error (run well) untuk program UAS pada Tulisan sebelumnya.

Bagi yang ingin mengetahui dimana sajakah letak-letak kesalahannya. Dapat berkomentar pada tulisan ini dengan mencantumkan Nama, NIM, dan Alamat E-Mail.

Terim Kasih


Code Input.java [Project - UAS]

import javax.microedition.lcdui.*;

class InputData
extends Form
implements ItemCommandListener, ItemStateListener, CommandListener
{
private Image image;
private Display display; 
private Command cmExit, cmSave, cmHapus, cmMF, cmTentang; 
private Alert al;
private UAS midlet;
private StringItem itemExit, itemSave, itemHapus, itemMF, itemTentang;
private TextField tfJudul, tfTanggal, tfIsi; 
private String storage = "UAS";
Ticker tk=new Ticker(":) NAMA : ......, NIM : ......, KELAS : .... :)");

public InputData(UAS midlet, Display display) {
super("Input Data");
this.display = display;
this.midlet = midlet;
this.setTicker(tk);
this.append("PROGRAM UAS SEMESTER GENAP 2013/2014"+"\n");
// this.append(""+"\n");
this.append("2 JULI 2014"+"\n");

cmSave = new Command("Simpan", Command.SCREEN, 1);
cmHapus = new Command("Hapus", Command.SCREEN, 2);
cmExit = new Command("Keluar", Command.SCREEN, 3);
cmMF = new Command("Manipulasi Form", Command.SCREEN, 4);
cmTentang = new Command("Tentang Aplikasi", Command.SCREEN,5);

//Method awal untuk menampilkan Foto 
this.display=display;
this.midlet=midlet;
try { image = image.createImage("/foto.png"); }
catch (java.io.IOException a){}
append(new ImageItem(null, image, ImageItem.LAYOUT_CENTER, null));
//Method akhir untuk menampilkan Foto 


tfJudul = new TextField("Judul", "", 255, TextField.ANY);
// this.append(tfJudul);

tfTanggal = new TextField("Tanggal", "", 30, TextField.ANY);
// this.append(tfTanggal);

tfIsi = new TextField("Kesan di Kelas Java", "", 255, TextField.ANY);
this.append(tfIsi);

itemSave = new StringItem(null, "Simpan", Item.BUTTON);
itemSave.setDefaultCommand(cmSave);
itemSave.setItemCommandListener(this);
append(itemSave);
setItemStateListener(this);

Save save = new Save(storage,255);
save.open();
//ini perintah untuk menyimpan data
String data = save.readRecord(2);
if(!data.equals("null")){
tfIsi.setString(data);
data = save.readRecord(3);
tfTanggal.setString(data);
data = save.readRecord(4);
tfJudul.setString(data);
itemHapus = new StringItem(null, "Hapus", Item.BUTTON);
itemHapus.setDefaultCommand(cmHapus);
itemHapus.setItemCommandListener(this);
append(itemHapus);
setItemStateListener(this);
}
save.close();

itemExit = new StringItem(null, "Keluar", Item.BUTTON);
itemExit.setDefaultCommand(cmExit);
itemExit.setItemCommandListener(this);
append(itemExit);
setItemStateListener(this);

itemMF = new StringItem(null, "Manipulasi Form", Item.BUTTON);
itemMF.setDefaultCommand(cmMF);
itemMF.setItemCommandListener(this);
append(itemMF);
setItemStateListener(this);

this.setCommandListener(this);


}

public void itemStateChanged(Item item) {
}

public void commandAction(Command c, Item item) {
if (c == cmSave) {
Save save = new Save(storage, 255);
save.open();
String temp = save.readRecord(2);
if(temp.equals("null")){
save.saveRecord(0,tfIsi.getString());
}else{
save.saveRecord(2,tfIsi.getString());
}
/* temp = save.readRecord(3);
if(temp.equals("null")){
save.saveRecord(0,tfTanggal.getString());
}else{
save.saveRecord(3,tfTanggal.getString());
}
temp = save.readRecord(4);
if(temp.equals("null")){
save.saveRecord(0,tfJudul.getString());
}else{
save.saveRecord(4,tfJudul.getString());
}**/
save.close();
al = new Alert("Konfirmasi", "Data Sudah Disimpan", null, AlertType.CONFIRMATION);
al.setTimeout(Alert.FOREVER);
display.setCurrent(al);

}else if(c == cmHapus){
Save save = new Save(storage, 255);
save.open();
String temp = save.readRecord(2);
String temp1 = save.readRecord(3);
String temp2 = save.readRecord(4);
save.saveRecord(2,"");
save.saveRecord(3,"");
save.saveRecord(4,"");

save.close();
tfJudul.setString("");
tfTanggal.setString("");
tfIsi.setString("");
al = new Alert("Konfirmasi", "Data Sudah Dihapus", null, AlertType.CONFIRMATION);
al.setTimeout(Alert.FOREVER);
display.setCurrent(al);

}else if(c == cmExit){
midlet.exitMIDlet();
}else if(c == cmMF){
ManipulasiForm MF = new ManipulasiForm(midlet, display);
display.setCurrent(MF);
}
}

public void commandAction(Command c, Displayable s) {
}

}

Senin, 30 Juni 2014

UAS Kelas Java Semester Genap 2013/2014

Untuk semua peserta UAS Kelas Java Semester Genap 2013/2014 harap mengikuti peraturan2 berikut ini:

1. Siapkan foto dengan Ukuran 96 x 96 Piksel seperti contoh gambar di bawah ini.



"Lihat Propertis dari gaambar ini"


2. Ubah nama gambar atau foto yang anda sudah siapkan menjadi "foto.png" untuk ekstensi gambar disesuaikan dengan gambar anda sesuai dengan propertis gambar anda, dalam hal ini adalah .png,,, juga bisa dengan .jpeg / .jpg / .bmp / .gif / dan lain-lain.

3. CopPas foto tersebut pda direktori "res" di Projek anda ... contoh : C:\Users\ASUS\j2mewtk\2.5.2\apps\UAS\res

4. Download Source Code Program ini dengan klik disini UAS.rar atau UAS.zip

5. Ekstrak File tersebut dan kemudian CopPas Foleder "UAS" ke C:\Uesrs\ .......... \j2mewtk\2.5.2\apps\

6. Selamat Mengerjakan

InputData.java

import javax.microedition.lcdui.*;

class InputData
extends Form
implements ItemCommandListener, ItemStateListener, CommandListener
{
private Image image;
private Display display; 
private Command cmExit, cmSave, cmHapus, cmMF, cmTentang; 
private Alert al;
private UAS midlet;
private StringItem itemExit, itemSave, itemHapus, itemMF, itemTentang;
private TextField tfJudul, tfTanggal, tfIsi; 
private String storage = "UAS";
Ticker ticker=new Ticker("");
Ticker tk=new Ticker(":) NAMA : ......, NIM : ......, KELAS : .... :)");

public InputData(UAS midlet, Display display) {
super("Input Data");
this.display = display;
this.midlet = midlet;
this.setTicker(ticker);
//
this.append("PROGRAM UAS SEMESTER GENAP 2013/2014"+"\n")
//
this.append("2 JULI 2014"+"\n");

cmSave = new Command("Simpan", Command.SCREEN, 1);
cmHapus = new Command("Hapus", Command.SCREEN, 2);
cmExit = new Command("Keluar", Command.SCREEN, 3);
cmMF = new Command("Manipulasi Form", Command.SCREEN, 4);
cmTentang = new Command("Tentang Aplikasi", Command.SCREEN,5);

//Method awal untuk menampilkan Foto 
this.display=display;
//
this.midlet=Midlet;
//
try { image = image.createImage("/foto.png"); }
catch (java.io.IOException a){}
append(new ImageItem(null, image, ImageItem.LAYOUT_LEFT, null));
//Method akhir untuk menampilkan Foto 


tfJudul = new TextField("Judul", "", 255, TextField.ANY);
// this.append(tfJudul);

tfTanggal = new TextField("Tanggal", "", 30, TextField.ANY);
// this.append(tfTanggal);

tfIsi = new TextField("Kesan di Kelas Java", "", 255, TextField.ANY);
this.append(tfIsi);

itemSave = new StringItem(null, "Simpan", Item.BUTTON);
itemSave.setDefaultCommand(cmSave);
itemSave.setItemCommandListener(this);
append(itemSave);
setItemStateListener(this);

Save save = new Save(storage,255);
save.open();
//ini perintah untuk menyimpan data

String data = save.readRecord(2);
if(!data.equals("null")){

tfIsi.setString("Teks Kosong");
data = save.readRecord(3);
tfTanggal.setString(data);
data = save.readRecord(4);
tfJudul.setString(data);
itemHapus = new StringItem(null, "Hapus", Item.BUTTON);
itemHapus.setDefaultCommand(cmHapus);
itemHapus.setItemCommandListener(this);
append(itemHapus);
setItemStateListener(this);
}
save.close();

itemExit = new StringItem(null, "Keluar", Item.BUTTON);
itemExit.setDefaultCommand(cmExit);
itemExit.setItemCommandListener(this);
append(itemExit);
setItemStateListener(this);

itemMF = new StringItem(null, "Manipulasi Form", Item.BUTTON);
itemMF.setDefaultCommand(cmMF);
itemMF.setItemCommandListener(this);
setItemStateListener(this);


/* 
this.setCommandListener(this);
**/

}

public void itemStateChanged(Item item) {
}

public void commandAction(Command c, Item item) {
if (c == cmSave) {
Save save = new Save(storage, 255);
save.open();
String temp = save.readRecord(2);
if(temp.equals("null")){
save.saveRecord(0,tfIsi.getString());
}else{
save.saveRecord(2,tfIsi.getString());
}
/* temp = save.readRecord(3);
if(temp.equals("null")){
save.saveRecord(0,tfTanggal.getString());
}else{
save.saveRecord(3,tfTanggal.getString());
}
temp = save.readRecord(4);
if(temp.equals("null")){
save.saveRecord(0,tfJudul.getString());
}else{
save.saveRecord(4,tfJudul.getString());
}**/
save.close();
al = new Alert("Konfirmasi", "Data Sudah Disimpan", null, AlertType.CONFIRMATION);
al.setTimeout(Alert.FOREVER);
display.setCurrent(al);

}else if(c == cmHapus){
Save save = new Save(storage, 255);
save.open();

String temp2 = save.readRecord(3);
String temp3 = save.readRecord(4);
save.saveRecord(2,"");
save.saveRecord(3,"");
save.saveRecord(4,"");

save.close();
tfJudul.setString("");
tfTanggal.setString("");
tfIsi.setString("");
al = new Alert("Konfirmasi", "Data Sudah Dihapus", null, AlertType.CONFIRMATION);
al.setTimeout(Alert.FOREVER);
display.setCurrent(al);

}else if(c == cmExit){
//
//midlet.exitMIDlet();
}else if(c == cmMF){
ManipulasiForm MF = new ManipulasiForm(midlet, display);

display.setCurrent(mF);
}
}

public void commandAction(Command c, Displayable s) {
}

}

Rabu, 30 April 2014

Manipulasi Form dan Turunannya dengan J2ME

Dalam setiap Program kita tentu mengenal istilah Form. Form adalah Layar Kosong atau juga dapat dikatakan sebuah Layer/Lapisan tampilan pada layar sebuah perangkat (HandPhone).
Kita bisa menaruh Ticker, TextFiled, Button dan lainnya pada sebuah Form.

Untuk pindah dari satu Form ke Form lainnya kita bisa memanfaatkan pemanggilan sebuah fungsi (objek).

Untuk lebih jelasnya berikut adalah Contoh Aplikasi sederhananya.

Buat projek baru dengan Sun Java Wireless Tool Kit 2.5.2.

Buat Nama Projek: Manipulasi Form
MIDlet Class : ManipulasiForm
Kemudian copy Source berikut ke lembar coding anda.

DiProjek ini ada soal Latihan yang jika anda bisa menyelesaikannya maka anda sudah menguasai manipulasi Form.
Terdapat 3 Menu Utama. 1 Menu ada yang tidak berfungsi. Buatlah agar Menu Tersebut BERFUNGSI


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

/**
* @author Win
*/
public class ManipulasiForm extends MIDlet implements CommandListener{
private Display display;
private Form form,form2,form3;
private Command isiData=new Command("Aplikasi Biodata", Command.EXIT, 1);
private Command tentang=new Command("Tentang Programmer", Command.EXIT, 1);
private Command keluar=new Command("Keluar", Command.EXIT, 1);
private Command home=new Command("HOME", Command.EXIT, 1);
private Command lihat=new Command("Lihat", Command.OK, 1);
private TextField user, password, nama, alamat, tlp;
Ticker tk=new Ticker("Aplikasi Manipulasi Form");

public ManipulasiForm(){
display=Display.getDisplay(this);
form=new Form("FORM HOME");
form.setTicker(tk);
form.append("Ini adalah Aplikasi Manipulasi Form"+"\n");
form.append("Silahkan Pilih Menu di Pojok Kanan "+"\n"+"\n");
form.append("1. Aplikasi Biodata ( Aplikasi Sederhana Biodata )"+"\n");
form.append("2. Tentang ( Data diri Programmer )"+"\n");
}



    public void home() {
form.addCommand(keluar);
form.addCommand(isiData);
form.addCommand(tentang);
form.setCommandListener(this);
display.setCurrent(form);
}

public void tentang(){

}

    public void startApp() {
home();
}

    public void pauseApp() {
}

    public void destroyApp(boolean unconditional) {
}

    public void form2(){
display=Display.getDisplay(this);

form2= new Form("FORM BIODATA");
form2.addCommand(lihat);
form2.addCommand(home);
form2.setCommandListener(this);

tk=new Ticker("ISI DENGAN DATA PRIBADI ANDA");
form2.setTicker(tk);


nama=new TextField("Nama : ", "",30, TextField.ANY);
form2.append(nama);
alamat=new TextField("Alamat :", "", 40, TextField.ANY);
form2.append(alamat);
tlp=new TextField("Telepon", "", 15, TextField.PHONENUMBER);
form2.append(tlp);


display.setCurrent(form2);

}

    public void lihat(){
form2.deleteAll();
tk=new Ticker("TERIMA KASIH");
form2.setTicker(tk);
form2.append("Berikut adalah data yang telah anda isikan\n");
form2.append("====================\n\n");
form2.append("Nama :"+nama.getString()+"\n");
form2.append("Alamat :"+alamat.getString()+"\n");
form2.append("Telepon :"+tlp.getString()+"\n");
display.setCurrent(form2);

}

public void commandAction(Command c, Displayable d) {
if(c==home){
home();
}else if(c==lihat){
lihat();
}else if(c==isiData){
form2();
}else if(c==tentang){
tentang();
}else if(c==keluar){
notifyDestroyed();
destroyApp(true);
}
}
}


Output:


Rabu, 26 Maret 2014

Membuat Aplikasi Phone Book Sederhana

Membuat Aplikasi Phone Book Sederhana


Berikut Codingnya

ProjectName : PhoneBook
ClassMIDLet : BukuTelepon


import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.rms.*;
import java.io.*;

public class BukuTelepon extends MIDlet implements CommandListener
{
private Display tampil;
private Form form;
private TextField txtNama,txtEmail,txtNoTelp;
private Command comSimpan,comKembali,comTampil,comUpdate,comHapus;
private int i = 0;

public BukuTelepon()
{

}

public void startApp()
{
tampil = Display.getDisplay(this);
form = new Form("Aplikasi Buku Telepon Suka - Suka");
txtNama = new TextField("Nama : ","",20,TextField.ANY); //String label,String text,int maxSize,Input Type
txtEmail = new TextField("Email : ","",30,TextField.ANY);
txtNoTelp = new TextField("No.Telp : ","",15,TextField.ANY);
comSimpan = new Command("Simpan",Command.OK,1);
comTampil = new Command("Tampil",Command.OK,2);
comUpdate = new Command("Update",Command.OK,3);
comHapus = new Command("Hapus",Command.OK,4);
comKembali = new Command("Kembali",Command.BACK,1);
form.append(txtNama); //Menambahkan textfield nama ke dalam form utama
form.append(txtEmail); //Menambahkan textfield email ke dalam form utama
form.append(txtNoTelp); //Menambahkan textfield no telepon ke dalam form utama
form.addCommand(comSimpan);
form.addCommand(comTampil);
form.addCommand(comUpdate);
form.addCommand(comHapus);
form.addCommand(comKembali);
form.setCommandListener(this);
tampil.setCurrent(form);

}
//Membuat method simpan
public void Simpan(String input1,String input2,String input3)
{
try
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
dos.writeUTF(input1);
dos.writeUTF(input2);
dos.writeUTF(input3);
dos.flush();
RecordStore rs = RecordStore.openRecordStore("bukutelepon",true); //bukutelepon sebagai nama database dalam konsep RMS
rs.addRecord(bos.toByteArray(),0,bos.toByteArray().length);
//Menutup koneksi
rs.closeRecordStore();
bos.close();
dos.close();
tampil.setCurrent(new Alert("Informasi","Data berhasil disimpan",null,AlertType.INFO));
}
catch(Exception ex)
{
ex.printStackTrace();
tampil.setCurrent(new Alert("Error","Data gagal disimpan",null,AlertType.ERROR));
}
}

//Membuat method update
public void Update(String input1,String input2,String input3,int i)
{
try
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
dos.writeUTF(input1);
dos.writeUTF(input2);
dos.writeUTF(input3);
dos.flush();
RecordStore rs = RecordStore.openRecordStore("bukutelepon",true);
rs.setRecord(i,bos.toByteArray(),0,bos.toByteArray().length);
rs.closeRecordStore();
bos.close();
dos.close();
tampil.setCurrent(new Alert("Informasi","Data berhasil diupdate",null,AlertType.INFO));
}
catch(Exception ex)
{
ex.printStackTrace();
tampil.setCurrent(new Alert("Informasi","Data gagal disimpan",null,AlertType.ERROR));
}

}
//Membuat method Hapus
public void Hapus(int i)
{
try
{
RecordStore rs = RecordStore.openRecordStore("bukutelepon",true);
rs.deleteRecord(i);
rs.closeRecordStore();
tampil.setCurrent(new Alert("Informasi","Data berhasil dihapus",null,AlertType.INFO));
}
catch(Exception ex)
{
ex.printStackTrace();
tampil.setCurrent(new Alert("Error","Data gagal dihapus",null,AlertType.ERROR));
}
}

public void pauseApp()
{
}

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

public void commandAction(Command cmd,Displayable display)
{
if(cmd == comKembali)
{
destroyApp(true);
}
else if(cmd == comSimpan)
{
//Method simpan
Simpan(txtNama.getString(),txtEmail.getString(),txtNoTelp.getString());
txtNama.setString("");
txtEmail.setString("");
txtNoTelp.setString("");
}
//Menampilkan data
else if(cmd == comTampil)
{
try
{
RecordStore rs = RecordStore.openRecordStore("bukutelepon",true);
int a;
for(a=1;a<=rs.getNumRecords();a++)
{
ByteArrayInputStream bis = new ByteArrayInputStream(rs.getRecord(a));
DataInputStream dis = new DataInputStream(bis);
String nama = dis.readUTF();
String email = dis.readUTF();
String telp = dis.readUTF();
bis.close();
dis.close();
System.out.println(nama + "\t" + email + "\t" + telp + "\t" + txtNama.getString().equals(nama));
if(txtNama.getString().equals(nama))
{
txtEmail.setString(email);
txtNoTelp.setString(telp);
i = a;
break;
}
}
rs.closeRecordStore();
}
catch(Exception ex)
{
ex.printStackTrace();
tampil.setCurrent(new Alert("Error",ex.getMessage(),null,AlertType.ERROR));
}
}
else if(cmd == comUpdate)
{
if(i>0)
{
//Method Update
Update(txtNama.getString(),txtEmail.getString(),txtNoTelp.getString(),i);
txtNama.setString("");
txtEmail.setString("");
txtNoTelp.setString("");
}
else
{
tampil.setCurrent(new Alert("Error","Data belum dipilih",null,AlertType.ERROR));
}
}
else if(cmd == comHapus)
{
if(i>0)
{
//Method Hapus
Hapus(i);
txtNama.setString("");
txtEmail.setString("");
txtNoTelp.setString("");
}
else
{
tampil.setCurrent(new Alert("Error","Data belum dipilih",null,AlertType.ERROR));
}
}
}
}