Home > Pemprograman > J2ME Graphics – Part 2 “Low Level vs High Level”

J2ME Graphics – Part 2 “Low Level vs High Level”

Pada bahasan sebelumnya kita sudah belajar mengenai dasar – dasar pemprograman graphics di Java. pada bahasan sekarang kita akan sama – sama belajar bagaimana menyatukan low level user interface dengan high level user interface karena pada hakikatnya UI di mobile terdiri atas low level dan highlevel.

Dengan menggunakan Highlevel, maka programmer tidak diharuskan mendesain , memformat, ataupun mengatur tampilan lagi dikarenakan sudah adanya default yang menyediakan, berbeda halnya jika menggunakan low level, maka programmer harus mendesain layout,tampilan per item / component. pada gambar sebelah kanan merupakan contoh low level dan sebelah kiri merupakan contoh highlevel

 

Berikut source code nya :

Midlet.Java


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Main;

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

/**
 * @author Octaviano
 */
public class Midlet extends MIDlet {
 private Display display;
 private HighLevel hl;
 private LowLevel ll;
 public Midlet() {
 this.display = Display.getDisplay(this);
 }

public void startApp() {
 aksesLow(null,null,null);
 display.setCurrent(ll);
 }

public void pauseApp() {
 }

public void destroyApp(boolean unconditional) {

}
 public void aksesLow(String nama,String alamat,String kelas)
 {
 ll = new LowLevel(display, this,nama,alamat,kelas);

display.setCurrent(ll);
 }
 public void aksesHigh()
 {
 hl = new HighLevel("Input Form",display, this);
 display.setCurrent(hl);
 }

}


LowLevel.Java

</pre>
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Main;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;

/**
 *
 * @author Octaviano
 */
public class LowLevel extends Canvas
{
 private Display display;
 private Midlet midlet;
 private String Nama;
 private String kelas;
 private String alamat;
 int nilai = 0xffffff;
 int button = 0;
 public LowLevel(Display display, Midlet midlet,String a,String b,String c) {
 this.display = display;
 this.midlet = midlet;
 this.Nama = a;
 this.kelas = c;
 this.alamat = b;
 setFullScreenMode(true);
 }

 protected void paint(Graphics g) {
 try
 {
 g.setColor(0x000000);
 g.drawRect(0, 0, getWidth(), getHeight());
 g.setColor(131,52,173);
 g.fillRect(0, 0, getWidth(), 40);
 g.fillRect(0, getHeight()-30, getWidth(), 30);
 g.setColor(0xFFFFFF);
 g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
 g.drawString("Hasil", getWidth()/2, 10, Graphics.TOP|Graphics.HCENTER);
 g.drawString("Nama : "+Nama, 10, 50, Graphics.TOP|Graphics.LEFT);
 g.drawString("Alamat :"+alamat, 10, 70, Graphics.TOP|Graphics.LEFT);
 g.drawString("Kelas :"+kelas,10, 90, Graphics.TOP|Graphics.LEFT);
 g.setColor(nilai);
 g.drawString("Edit", 10, getHeight()-10, Graphics.BOTTOM|Graphics.LEFT);
 g.drawString("Exit", getWidth()-10, getHeight()-10, Graphics.BOTTOM|Graphics.RIGHT);
 System.out.println("Button : "+button);
 }
 catch(Exception e)
 {
 System.out.println("Error : "+e.getMessage());
 }
 }

protected void keyPressed(int keyCode) {
 button = keyCode;
 switch(keyCode)
 {
 case -6:
 midlet.aksesHigh();
 break;
 }
 repaint();
 }
}
<pre>

HighLevel.Java

</pre>
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Main;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.TextField;

/**
 *
 * @author Octaviano
 */
public class HighLevel extends Form implements CommandListener{
 private Display display;
 private Midlet midlet;
 private Form form;
 private Command cmdInput;
 private Command cmdBack;
 private TextField textnama;
 private TextField alamat;
 private ChoiceGroup kelas;
 String nama,jurusan,alamat2;
 public HighLevel(String nama,Display display,Midlet midlet) {
 super(nama);
 this.display = display;
 this.midlet = midlet;
 cmdInput = new Command("Selesai", Command.OK, 1);
 cmdBack = new Command("Kembali", Command.OK, 2);
 addCommand(cmdInput);
 addCommand(cmdBack);
 setCommandListener(this);
 textnama = new TextField("Masukan Nama", "", 50, TextField.PLAIN);
 alamat = new TextField("Masukan Alamat : ", "", 255, TextField.PLAIN);
 kelas = new ChoiceGroup("Kelas", Choice.EXCLUSIVE);
 kelas.append("TMD", null);
 kelas.append("Tikes", null);
 this.append(textnama);
 this.append(alamat);
 this.append(kelas);

 }

public void commandAction(Command c, Displayable d) {
 if(c==cmdBack)
 {
 getData();
 }
 if(c==cmdInput)
 {

 }
 }
 public void getData()
 {
 Encapsulasi en = new Encapsulasi();
 en.setAlamat(alamat.getString());
 en.setNama(textnama.getString());
 en.setKelas(kelas.getString(kelas.getSelectedIndex()));
 midlet.aksesLow(en.getNama(),en.getAlamat(),en.getKelas());
 }

}
<pre>

Encapsulasi.Java

</pre>
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Main;

/**
 *
 * @author Octaviano
 */
public class Encapsulasi {
 String nama,kelas,alamat;
 public Encapsulasi() {

}
 public void setNama(String nama)
 {
 this.nama = nama;
 }
 public void setKelas(String kelas)
 {
 this.kelas = kelas;
 }
 public void setAlamat(String alamat)
 {
 this.alamat = alamat;
 }
 public String getNama()
 {
 return this.nama;
 }
 public String getAlamat()
 {
 return this.alamat;
 }
 public String getKelas()
 {
 return this.kelas;
 }
}
<pre>
Categories: Pemprograman
  1. No comments yet.
  1. No trackbacks yet.

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