IT INFORMATION

Buku Tamu

//—-Kode Buku Tamu anda di sini—–

Menggunakan migration codeigniter 2x

Selamat malam sahabat blogger. wah sudah lama sekali saya tidak pernah membuka blog ini, rasanya kangen, jadinya saya buka lagi deh......
ok, kali ini saya ingin sharing dengan teman-teman yang sedang belajar codeigniter. sekarang saya akan membahas mengenai migration, apa sebenarnya fungsi dari migration dan bagaimana cara menggunakannya.
so, cekidot.....

fungsi migrasi adalah untuk memanagemen tabel dalam database

mari kita lihat bagaimana cara membuatnya.
sebelumnya pastikan kita sudah membuat database baru di localhost. misal namanya adalah coba
buat folder baru beranama development dalam folder aplication/config kemudian cut file database.php yang ada dalam folder aplication/config
seperti ini
kemudian ubah file database.php menjadi seperti berikut ini
//============================================================
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| DATABASE CONNECTIVITY SETTINGS
| -------------------------------------------------------------------
| This file will contain the settings needed to access your database.
|
| For complete instructions please consult the 'Database Connection'
| page of the User Guide.
|
| -------------------------------------------------------------------
| EXPLANATION OF VARIABLES
| -------------------------------------------------------------------
|
| ['hostname'] The hostname of your database server.
| ['username'] The username used to connect to the database
| ['password'] The password used to connect to the database
| ['database'] The name of the database you want to connect to
| ['dbdriver'] The database type. ie: mysql.  Currently supported:
 mysql, mysqli, postgre, odbc, mssql, sqlite, oci8
| ['dbprefix'] You can add an optional prefix, which will be added
|  to the table name when using the  Active Record class
| ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
| ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
| ['cache_on'] TRUE/FALSE - Enables/disables query caching
| ['cachedir'] The path to the folder where cache files should be stored
| ['char_set'] The character set used in communicating with the database
| ['dbcollat'] The character collation used in communicating with the database
|  NOTE: For MySQL and MySQLi databases, this setting is only used
 as a backup if your server is running PHP < 5.2.3 or MySQL < 5.0.7
|  (and in table creation queries made with DB Forge).
 There is an incompatibility in PHP with mysql_real_escape_string() which
 can make your site vulnerable to SQL injection if you are using a
 multi-byte character set and are running versions lower than these.
 Sites using Latin-1 or UTF-8 database character set and collation are unaffected.
| ['swap_pre'] A default table prefix that should be swapped with the dbprefix
| ['autoinit'] Whether or not to automatically initialize the database.
| ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections
| - good for ensuring strict SQL while developing
|
| The $active_group variable lets you choose which connection group to
| make active.  By default there is only one group (the 'default' group).
|
| The $active_record variables lets you determine whether or not to load
| the active record class
*/

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'gua';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = TRUE;


/* End of file database.php */
/* Location: ./application/config/database.php */
//========================================================




















migration.php
//========================================================
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| Enable/Disable Migrations
|--------------------------------------------------------------------------
|
| Migrations are disabled by default but should be enabled
| whenever you intend to do a schema migration.
|
*/
$config['migration_enabled'] = TRUE;


/*
|--------------------------------------------------------------------------
| Migrations version
|--------------------------------------------------------------------------
|
| This is used to set migration version that the file system should be on.
| If you run $this->migration->latest() this is the version that schema will
| be upgraded / downgraded to.
|
*/
$config['migration_version'] = 1;


/*
|--------------------------------------------------------------------------
| Migrations Path
|--------------------------------------------------------------------------
|
| Path to your migrations folder.
| Typically, it will be within your application path.
| Also, writing permission is required within the migrations path.
|
*/
$config['migration_path'] = APPPATH . 'migrations/';


/* End of file migration.php */
/* Location: ./application/config/migration.php */
//=======================================================



















//=======================================================
<?php
class Migration_Create_users extends CI_Migration {

public function up()
{
$this->dbforge->add_field(array(
'id' => array(
'type' => 'INT',
'constraint' => 11,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'email' => array(
'type' => 'VARCHAR',
'constraint' => '100',
),
'password' => array(
'type' => 'VARCHAR',
'constraint' => '128',
),
'name' => array(
'type' => 'VARCHAR',
'constraint' => '100',
),
));
$this->dbforge->add_key('id');
$this->dbforge->create_table('users');
}

public function down()
{
$this->dbforge->drop_table('users');
}
}
?>
//==============================================================









//==============================================================
<?php
class Migration extends CI_Controller
{

public function __construct ()
{
parent::__construct();
}

public function index ()
{
$this->load->library('migration');
if (! $this->migration->current()) {
show_error($this->migration->error_string());
}
else {
echo 'Migration worked!';
}

}
}
?>
//==================================================









Game Sederhana J2ME

Selamat malam sahabat blogku yang setia, apa kabarnya? semoga baik -  baik aja. rasanya sudah lama sahabat, saya ndak posting "sesuatu" di blog ini. nah...,sekarang saya mau memberikan sesuatu kepada sahabat blog tentang permainan di java mobile. udah gak sabar ya, sekarang kita langsung aja ke TKP.
untuk membuat suatu game kita memerlukan
1. skenario
2. source code
3. testing

kebetulan kemarin saya nemu diinternet game sederhana tentang J2ME. yang kurang lebih begini nih tampilannya....,















berikut source codenya :
1. Principal.java

/**
 * @author rodrigo.silva
 */
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.*;

public class Principal extends MIDlet implements CommandListener {

    private Command sairC;
    private Command iniciarC;
    Principal pri;
    Display dis;
    Jogo canvas;
    Intro introducao;

    public Principal() {
        this.canvas = new Jogo();
        this.introducao = new Intro();
        sairC = new Command("Sair", Command.EXIT, 0);
        iniciarC = new Command("Iniciar", Command.OK, 1);
    }

    public void startApp() {
        this.dis = Display.getDisplay(this);
        this.introducao.addCommand(sairC);
        this.introducao.addCommand(iniciarC);
        this.introducao.setCommandListener(this);
        dis.setCurrent(introducao);
    }

    public void pauseApp() {
    }

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

    public void commandAction(Command c, Displayable d) {
        if (d == introducao) {
            if (c == sairC) {
                destroyApp(true);
            }
            if (c == iniciarC) {
                novoGame();
            }
        }
        if (d == canvas) {
            if (c == sairC) {
                dis.setCurrent(introducao);
            }
            if (c == iniciarC) {
                novoGame();
            }
        }
    }

    public void novoGame() {
        canvas = new Jogo();
        this.canvas.addCommand(sairC);
        this.canvas.addCommand(iniciarC);
        this.canvas.setCommandListener(this);
        dis.setCurrent(canvas);
    }
}


2. Game.java
/**
 *
 * @author Rodrigo Caetano Silva
 */
import java.util.Random;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Game extends Canvas {

    public  boolean colisao(Personagem v, Personagem p) {
        boolean colision = false;
        colision = (v.getY2() >= p.getY()) && (v.getY() < p.getY2()) ? !((v.getX() > p.getX2()) || (v.getX2() < p.getX())) ? true : false : false;
        return colision;
    }

    public int randomize(int min, int max) {
        int randomize = 0;
        int f = -1;
        while (f < min) {
            Random r = new Random();
            f = ((r.nextInt() & 0xffff) * 180) >> 16;
            randomize = f > 20 ? f : 0;
        }
        return randomize;
    }

    public void desenha(Graphics g, int x, int y, int larg, int alt, Image imagem) {
        g.drawImage(imagem, x, y, Graphics.VCENTER | Graphics.RIGHT);
    }

    protected void paint(Graphics g) {
       
    }

  
}


3. Intro.java

import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Intro extends Canvas implements Runnable {

    private Image roccaImg;
    private Image fundoImg;
    boolean intro;
    Personagem rocca;
    Personagem fundo;
    int alt;
    int larg;
    int vilaoX;
    int vilaoY;
    public Intro() {
        vilaoX = 20;
        vilaoY = 0;
        intro = true;
        larg = getWidth();
        alt = getHeight();
        try {
            this.roccaImg = Image.createImage("/imagem/logo.png");
            this.fundoImg = Image.createImage("/imagem/rocket.png");
            rocca = new Personagem(120, 100, 70, 25, roccaImg);
            fundo = new Personagem(180, 100, 100, 0, fundoImg);
            rocca.setImg(roccaImg);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        new Thread(this).start();
    }

    protected void paint(Graphics g) {
        fundo.desenha(g);
        rocca.desenha(g);
    }

    public void run() {
        int velX = 2;
        int velY = 2;
        while (intro) {
            try {
                Thread.sleep(50);
                rocca.setAll(rocca.getX()+velX,rocca.getY()+velY);
                if ((rocca.getX() + 1) > larg || (rocca.getX() < 70)) {
                    velX = -velX;
                }
                if ((rocca.getY() + 30) > alt || (rocca.getY()< 10)) {
                    velY = -velY;
                }
               
                repaint();
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    }
}


4. Jogo.java

/**
 *
 * @author Rodrigo Caetano Silva
 */
import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Jogo extends Game implements Runnable {

    Personagem heroi;
    Personagem vilao;
    Personagem tiroEsq;
    Personagem tiroDir;
    Personagem fundo;
    int dir;
    int vida;
    int tiroDirY;
    int tiroDirX;
    int tiroEsqY;
    int tiroEsqX;
    boolean efetuouDisparo;
    public int larg;
    boolean statusTiroDir;
    boolean statusTiroEsq;
    int velVilaoX;
    int velVilaoY;
    private boolean controle;
    private boolean game;
    public int alt;
    public int pontos;
    public int pontosIncre;
    public int nivel;
    private Image alienImg;
    private Image balaImg;
    private Image heroiImg;
    private Image fundoImg;

    public Jogo() {
        vida =3;
        velVilaoX = 5;
        velVilaoY = 5;
        efetuouDisparo = false;
        statusTiroDir = false;
        game = true;
        larg = getWidth();
        alt = getHeight();
        pontosIncre = 100;
        pontos = 0;
        nivel = 0;
        imagens("/imagem/alien.png", "/imagem/tiro.png", "/imagem/fundo.png", "/imagem/fog.png");
        fundo = new Personagem(180, 100, 100, 0, fundoImg);
        heroi = new Personagem(larg - 120, alt - 50, 20, 20, heroiImg);
        vilao = new Personagem(100, 0, 20, 30, alienImg);
        tiroDir = new Personagem(heroi.getX() + 5, heroi.getY(), 20, 20, balaImg);
        tiroEsq = new Personagem(heroi.getX() - 15, heroi.getY(), 10, 10, balaImg);
        new Thread(this).start();
    }

    protected void paint(Graphics g) {
        fundo.desenha(g);
        atualizaPersonagens(g);
        nivel();
        infoGame(g);
        disparo(g);
        heroi.desenha(g);
        vilao.desenha(g);
        tiroDir.desenha(g);
        tiroEsq.desenha(g);
        statusGame(g);
    }

    private void atualizaPersonagens(Graphics g) {
        vida = colisao(vilao, heroi)?vida=vida-1:vida;
        game = vida<=0?false:true;
        if (colisao(vilao, tiroDir) || colisao(vilao, tiroEsq)) {
            vilao.setAll(randomize(30, 160), 0);
            pontos = pontos + pontosIncre;
        }
        velocidadeNiveis();
        vilao.setAll(vilao.getY() > 220 ? randomize(20, 180) : vilao.getX(), vilao.getY() > 220 ? 0 : vilao.getY());
        tiroDir.setAll(heroi.getX() + 3, heroi.getY());
        tiroEsq.setAll(heroi.getX() - 15, heroi.getY());
    }

    private void velocidadeNiveis() {
        if (nivel == 0) {
            velVilaoY = 2;
            vilao.setY(vilao.getY() + velVilaoY);
        }
        if (nivel == 1) {
            velVilaoY = 3;
            vilao.setY(vilao.getY() + velVilaoY);
        }
        if (nivel == 2) {
            velVilaoY = 5;
            vilao.setY(vilao.getY() + velVilaoY);
        }
        if(nivel == 3){
            defineComoCair(5, 5, 0, 0);
        }
        if(nivel == 4){
            defineComoCair(5, 5, 0, 0);
        }
    }

    private void defineComoCair(int x, int y, int p, int z) {
        if ((vilao.getX() + x) > larg || (vilao.getX() - 20 < p)) {
            velVilaoX = -velVilaoX;
        }
        if ((vilao.getY() + y) > alt || (vilao.getY() < z)) {
            velVilaoY = -velVilaoY;
        }
        vilao.setAll(vilao.getX() + velVilaoX, vilao.getY() + velVilaoY);
    }

    public void run() {
        while (game) {
            try {
                Thread.sleep(50);
                if (controle) {
                    switch (dir) {
                        case UP:
                            heroi.setY(heroi.getY() < 0 ? 200 : heroi.getY() - 15);
                            break;
                        case DOWN:
                            heroi.setY(heroi.getY() > 200 ? 0 : heroi.getY() + 15);
                            break;
                        case LEFT:
                            heroi.setX(heroi.getX() < 15 ? 180 : heroi.getX() - 15);
                            break;
                        case RIGHT:
                            heroi.setX(heroi.getX() > 180 ? 15 : heroi.getX() + 15);
                            break;
                        case FIRE:
                            efetuouDisparo = true;
                    }
                }
                repaint();
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    }

    private void imagens(String imgAlien, String imgBala, String imgFundo, String imgHeroi) {
        try {
            if (!imgAlien.equals("")) {
                this.alienImg = Image.createImage(imgAlien);
                if (vilao != null) {
                    vilao.setImg(this.alienImg);
                }
            }
            if (!imgBala.equals("")) {
                this.balaImg = Image.createImage(imgBala);
            }
            if (!imgFundo.equals("")) {
                this.fundoImg = Image.createImage(imgFundo);
                if (fundo != null) {
                    fundo.setImg(this.fundoImg);
                }
            }
            if (!imgHeroi.equals("")) {
                this.heroiImg = Image.createImage(imgHeroi);
                if (heroi != null) {
                    heroi.setImg(this.heroiImg);
                }
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }

    public void nivel() {
        this.nivel = this.nivel == -1 ? 0 : this.nivel;
        this.pontos = this.nivel == -1 ? 0 : this.pontos;
        this.nivel = this.pontos > 2000 ? 1 : this.nivel;
        this.nivel = this.pontos > 5000 ? 2 : this.nivel;
        this.nivel = this.pontos > 10000 ? 3 : this.nivel;
        this.nivel = this.pontos > 25000 ? 4 : this.nivel;
        if (this.nivel == 0) {
            pontosIncre = 100;
            imagens("/imagem/alien.png", "/imagem/tiro.png", "/imagem/fundo.png", "/imagem/fog.png");
        }
        if (this.nivel == 1) {
            pontosIncre = 200;
            imagens("/imagem/alienNivel2.png", "/imagem/tiro.png", "/imagem/fundo1.png", "/imagem/fog.png");
        }
        if (this.nivel == 2) {
            pontosIncre = 300;
            imagens("/imagem/alienNivel3.png", "/imagem/tiro.png", "/imagem/fundo2.png", "/imagem/fog.png");
        }
        if (this.nivel == 3) {
            pontosIncre = 500;
            imagens("/imagem/alienNivel4.png", "/imagem/tiro.png", "/imagem/fundo5.png", "/imagem/fog.png");
        }
        if (this.nivel == 4) {
            pontosIncre = 500;
            imagens("/imagem/logo.png", "", "/imagem/rocket.png", "/imagem/fog.png");
        }
    }

    private void infoGame(Graphics g) {
        g.setColor(0xFFFAFA);
        g.drawString("Nivel : " + nivel, 0, 0, Graphics.LEFT | Graphics.TOP);
        g.drawString("Pontos : " + pontos, 0, 10, Graphics.LEFT | Graphics.TOP);
        g.drawString("Vida : " + vida, 0, 20, Graphics.LEFT | Graphics.TOP);
    }

    private void disparo(Graphics g) {
        if (efetuouDisparo) {
            if (!statusTiroDir) {
                tiroDirY = tiroDir.getY();
                tiroDirX = tiroDir.getX();
                statusTiroDir = true;
            } else {
                if (!statusTiroEsq) {
                    tiroEsqY = tiroEsq.getY();
                    tiroEsqX = tiroEsq.getX();
                    statusTiroEsq = true;
                }
            }
            efetuouDisparo = false;
        }
        if (statusTiroDir) {
            if (tiroDirY < 0) {
                tiroDirY = tiroDir.getY();
                tiroDirX = tiroDir.getX();
                statusTiroDir = false;
            }

            tiroDirY = tiroDirY - 15;
            tiroDir.setAll(tiroDirX, tiroDirY);
        }
        if (statusTiroEsq) {
            if (tiroEsqY < 0) {
                tiroEsqY = tiroEsq.getY();
                tiroEsqX = tiroEsq.getX();
                statusTiroEsq = false;
            }
            tiroEsqY = tiroEsqY - 15;
            tiroEsq.setAll(tiroEsqX, tiroEsqY);
        }
    }

    public void statusGame(Graphics g) {
        if (!game) {
            game = false;
            controle = false;
            g.setColor(0xFFFAFA);
            g.drawString("YOU LOSE", 50, 100, Graphics.LEFT | Graphics.TOP);
        } else {
            if (nivel == 4) {
                vida = 999;
                g.setColor(0x000000);
                g.drawString("CONGRATULATIONS", 30, 90, Graphics.LEFT | Graphics.TOP);
                g.drawString("YOU WIN", 50, 100, Graphics.LEFT | Graphics.TOP);
            }
        }
    }

    public void keyPressed(int key) {
        dir = getGameAction(key);
        controle = true;
    }

    public void keyReleased(int key) {
        controle = false;
        dir = -999;
    }
}


5. Personagem.java
/**
 *
 * @author Rodrigo Caetano Silva
 */
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Personagem {

    int x, y, x2, y2, tamX, tamY;
    Image img;

    public Personagem(int x, int y, int tamX, int tamY, Image img) {
        this.x = x;
        this.y = y;
        this.tamX = tamX;
        this.tamY = tamY;
        this.img = img;
        this.x2 = x + tamX;
        this.y2 = y + tamY;
    }

    Personagem(int i, int i0, int i1, int i2, String string) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    public int getTamX() {
        return tamX;
    }

    public void setTamX(int tamX) {
        this.tamX = tamX;
    }

    public int getTamY() {
        return tamY;
    }

    public void setTamY(int tamY) {
        this.tamY = tamY;
    }

    public Image getImg() {
        return img;
    }

    public void setImg(Image img) {
        this.img = img;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
        this.x2 = x + tamX;
    }

    public int getX2() {
        return x2;
    }

    public void setX2(int x2) {
        this.x2 = x2;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
        this.y2 = y + tamY;
    }

    public int getY2() {
        return y2;
    }

    public void setY2(int y2) {
        this.y2 = y2;
    }

    public void setAll(int x, int y) {
        this.x = x;
        this.y = y;
        this.x2 = x + tamX;
        this.y2 = y + tamY;
    }

    protected void desenha(Graphics g) {
        g.drawImage(this.img, x, y, Graphics.VCENTER | Graphics.RIGHT);
    }
}


semoga bermanfaat :)

untuk source code lengkapnya klik disini

RMS pada Java Mobile

Selamat pagi sahabat blogku yang setia, semoga pagi yang cerah ini menambah semangat kita untuk selalu berkreasi dan berperan aktif demi masa depan yang cerah. begini sahaba blog, bentar lagi kan ada UTS tentang mobile computing nih, utsnya tentang RMS. ane mau memberikan sedikit pencerahan pada sahabat blog. tentang RMS kemarin sudah ane jelaskan sekarang ane mau memberikan referensi pada sahabat blog, kali aja berguna...., jangan bilang - bilang ya, source code yang dibawah ini ngopy dari internet. hehehe
cuma buat referensi gak apa - apa kan? sudah ndak sabar ya pengen lihat gimana jadinya, mari kita lihat bersama sama.....,















































setelah sahabat melihat tampilan emulatornya, sekarang mari simak source codenya

import javax.microedition.rms.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.io.*;
    
    public class DaftarGajiKaryawan extends MIDlet implements CommandListener {
    
        Display display;
        Alert alert;
        Form formMotto,formUtama, formTambahData, formLihat, formEdit, formCari,formBank;
        List list;
        RecordStore recordstore = null;
        RecordEnumeration recordEnumeration = null;
        Penyaring filter = null;
        Ticker tik;
      
        Command cmdBank=new Command ("Tentang Bank",Command.OK,3);
        Command cmdMotto=new Command ("Motto Bank",Command.OK,2);
        Command cmdKeluar = new Command("Keluar", Command.EXIT, 1);
        Command cmdLihatData = new Command("Lihat Data", Command.SCREEN, 1);
        Command cmdDataBaru = new Command("Tambahkan Data", Command.SCREEN, 1);
        Command cmdEdit = new Command("Edit Data", Command.SCREEN, 1);
        Command cmdHapus = new Command("Hapus Data", Command.SCREEN, 1);
        Command cmdFind = new Command("Cari Karyawan", Command.SCREEN, 2);
        Command cmdCari = new Command("Cari", Command.SCREEN, 1);
        Command cmdSimpan = new Command("Simpan", Command.SCREEN, 1);
        Command cmdUbah = new Command("Edit", Command.SCREEN, 1);
        Command cmdCancel = new Command("Kembali", Command.BACK, 1);
        Command cmdBack = new Command("Kembali", Command.BACK, 1);
        Command cmdKembali=new Command("Kembali",Command.BACK,1);
              
        TextField txtNama = new TextField("Nama:", "", 20, TextField.ANY);
        TextField txtNIK = new TextField("NIK:", "", 30, TextField.PHONENUMBER);
        TextField txtJabatan = new TextField("Jabatan:", "", 20, TextField.ANY);
        TextField txtGaji = new TextField("Gaji:", "", 30, TextField.PHONENUMBER);
        TextField txtRecNama, txtRecNIK, txtRecJabatan, txtRecGaji;
        TextField txtFind = new TextField("Masukkan Nama Karyawan:", "", 20, TextField.ANY);
     
        int recID, currentTask;
        String keyword;
      
   
        public DaftarGajiKaryawan() {
            tik = new Ticker("Aplikasi Pendataan karyawan Bank BRI");
          
            formMotto=new Form("Motto Bank BRI");
            formMotto.append("=================================");
            formMotto.append("\" Melayani Dengan Setulus Hati\"");
            formMotto.append("=================================");
            formMotto.setTicker(tik);
            formMotto.addCommand(cmdKembali);
            formMotto.setCommandListener(this);
          
            formUtama = new Form("");
            try {
                Image img = Image.createImage("/java mobile perbaungan.jpg");
                ImageItem image = new ImageItem("", img, Item.LAYOUT_CENTER, "Data Karyawan");
                formUtama.append(image);
            } catch (Exception e) {
                e.printStackTrace();
            }
            formUtama.addCommand(cmdLihatData);
            formUtama.addCommand(cmdKeluar);
            formUtama.addCommand(cmdBank);
            formUtama.addCommand(cmdMotto);
            formUtama.addCommand(cmdDataBaru);
            formUtama.setCommandListener(this);
    
           
            formTambahData = new Form("Tambah Data Karyawan");
            formTambahData.addCommand(cmdBack);
            formTambahData.addCommand(cmdSimpan);
            formTambahData.append(txtNama);
            formTambahData.append(txtNIK);
            formTambahData.append(txtJabatan);
            formTambahData.append(txtGaji);
            formTambahData.setTicker(tik);
            formTambahData.setCommandListener(this);
    
            formCari = new Form("Cari Data Karyawan");
            formCari.addCommand(cmdBack);
            formCari.addCommand(cmdCari);
            formCari.append(txtFind);
            formCari.setTicker(tik);
            formCari.setCommandListener(this);
          
          
            formBank=new Form("Tentang Bank");
            formBank.append("Bank Rakyat Indonesia (BRI) adalah salah satu bank milik pemerintah" +
                    " yang terbesar di Indonesia. Pada awalnya Bank Rakyat Indonesia (BRI)" +
                    " didirikan di Purwokerto, Jawa Tengah oleh Raden Bei Aria Wirjaatmadja dengan" +
                    " nama De Poerwokertosche Hulp en Spaarbank der Inlandsche Hoofden atau \"Bank" +
                    " Bantuan dan Simpanan Milik Kaum Priyayi Purwokerto\", suatu lembaga keuangan" +
                    " yang melayani orang-orang berkebangsaan Indonesia (pribumi). Lembaga tersebut" +
                    " berdiri tanggal 16 Desember 1895, yang kemudian dijadikan sebagai hari kelahiran BRI.");
            formBank.addCommand(cmdKembali);
            formBank.setTicker(tik);
            formBank.setCommandListener(this);
        }
    
        public void startApp() {
            if (display == null) {
                display = Display.getDisplay(this);
                display.setCurrent(formUtama);
            }
        }
    
        public void pauseApp() {
        }
         public class Pembanding implements RecordComparator {
    
        private byte[] comparatorInputData = new byte[300];
        private ByteArrayInputStream comparatorInputStream = null;
        private DataInputStream comparatorInputDataType = null;
    
        public int compare(byte[] record1, byte[] record2) {
            int record1int, record2int;
            try {
                comparatorInputStream = new ByteArrayInputStream(record1);
                comparatorInputDataType = new DataInputStream(comparatorInputStream);
                String data1 = comparatorInputDataType.readUTF();
                comparatorInputStream = new ByteArrayInputStream(record2);
                comparatorInputDataType = new DataInputStream(comparatorInputStream);
                String data2 = comparatorInputDataType.readUTF();
                int comparison = data1.compareTo(data2);
                if (comparison == 0) {
                    return RecordComparator.EQUIVALENT;
                } else if (comparison < 0) {
                    return RecordComparator.PRECEDES;
                } else {
                    return RecordComparator.FOLLOWS;
                }
            } catch (Exception error) {
                return RecordComparator.EQUIVALENT;
            }
        }
    
        public void compareClose() {
            try {
                if (comparatorInputStream != null) {
                    comparatorInputStream.close();
                }
                if (comparatorInputDataType != null) {
                    comparatorInputDataType.close();
                }
            } catch (Exception error) {
            }
        }
    }
      
      
      public class Penyaring implements RecordFilter {
    
        private String search = null;
        private ByteArrayInputStream inputstream = null;
        private DataInputStream datainputstream = null;
    
        public Penyaring(String search) {
            this.search = search.toLowerCase();
        }
    
        public boolean matches(byte[] suspect) {
            String string = new String(suspect).toLowerCase();
            if (string != null && string.indexOf(search) != -1) {
                return true;
            } else {
                return false;
            }
        }
    
        public void filterClose() {
            try {
                if (inputstream != null) {
                    inputstream.close();
                }
                if (datainputstream != null) {
                    datainputstream.close();
                }
            } catch (Exception error) {
            }
        }
    }
        public void destroyApp(boolean unconditional) {
        }
    
        public void commandAction(Command c, Displayable d) {
           
            try {
                recordstore = RecordStore.openRecordStore("DataKaryawanRS", true);
            } catch (Exception error) {
                alert = new Alert("Error Creating", error.toString(), null, AlertType.WARNING);
                alert.setTimeout(Alert.FOREVER);
                display.setCurrent(alert);
            }
    
          
        if (c == cmdKeluar) {
                destroyApp(true);
                notifyDestroyed();
            }
    
          
            if (c == cmdBack) {
                display.setCurrent(list);
            }
    
          
            if (c == cmdCancel) {
                display.setCurrent(formUtama);
            }
          
            if (c == cmdBank) {
                display.setCurrent(formBank);
            }
          
             if (c == cmdMotto) {
                display.setCurrent(formMotto);
            }
          
            if (c == cmdKembali) {
                display.setCurrent(formUtama);
            }
    
          
            if (c == cmdDataBaru) {
                txtNama.setString("");
                txtNIK.setString("");
                txtJabatan.setString("");
                txtGaji.setString("");
                display.setCurrent(formTambahData);
            }
    
          
            if (c == cmdFind) {
                txtFind.setString("");
                display.setCurrent(formCari);
            }
    
          
            if (c == cmdCari) {
                keyword = txtFind.getString();
                try {
                    list = new List("Nama-Nama Karyawan", List.IMPLICIT);
                    list.addCommand(cmdDataBaru);
                    list.addCommand(cmdFind);
                    list.addCommand(cmdCancel);
                    list.setTicker(tik);
                    list.setCommandListener(this);
                    currentTask = 1;
                    String inputName = null;
                    byte[] byteInputData = new byte[300];
                    ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData);
                    DataInputStream inputDataStream = new DataInputStream(inputStream);
                    if (recordstore.getNumRecords() > 0) {
                        filter = new Penyaring(keyword);
                        recordEnumeration = recordstore.enumerateRecords(filter, null, false);
                        while (recordEnumeration.hasNextElement()) {
                            recordstore.getRecord(recordEnumeration.nextRecordId(), byteInputData, 0);
                            inputName = inputDataStream.readUTF();
                            list.append(inputName + "", null);
                            inputStream.reset();
                        }
                    }
                    display.setCurrent(list);
                    inputStream.close();
                } catch (Exception error) {
                    alert = new Alert("Error Reading",
                            error.toString(), null, AlertType.WARNING);
                    alert.setTimeout(Alert.FOREVER);
                    display.setCurrent(alert);
                }
            }
    
          
            if (c == cmdSimpan) {
                try {
                    String outputNama = txtNama.getString();
                    String outputNIK = txtNIK.getString();
                    String outputJabatan = txtJabatan.getString();
                    String outputGaji = txtGaji.getString();
                    byte[] outputRecord;
                    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                    DataOutputStream outputDataStream = new DataOutputStream(outputStream);
                    outputDataStream.writeUTF(outputNama);
                    outputDataStream.writeUTF(outputNIK);
                    outputDataStream.writeUTF(outputJabatan);
                    outputDataStream.writeUTF(outputGaji);
                    outputDataStream.flush();
                    outputRecord = outputStream.toByteArray();
                    recordstore.addRecord(outputRecord, 0, outputRecord.length);
                    outputStream.reset();
                    outputStream.close();
                    outputDataStream.close();
                    display.setCurrent(formUtama);
                } catch (Exception error) {
                    display.setCurrent(alert);
                }
            }
    
          
            if (c == cmdUbah) {
                try {
                    String outputNama = txtRecNama.getString();
                    String outputNIK = txtRecNIK.getString();
                    String outputJabatan = txtRecJabatan.getString();
                    String outputGaji = txtRecGaji.getString();
                    byte[] outputRecord;
                    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                    DataOutputStream outputDataStream = new DataOutputStream(outputStream);
                    outputDataStream.writeUTF(outputNama);
                    outputDataStream.writeUTF(outputNIK);
                    outputDataStream.writeUTF(outputJabatan);
                    outputDataStream.writeUTF(outputGaji);
                    outputDataStream.flush();
                    outputRecord = outputStream.toByteArray();
                    recordstore.setRecord(recID, outputRecord, 0, outputRecord.length);
                    outputStream.reset();
                    outputStream.close();
                    outputDataStream.close();
                    display.setCurrent(formUtama);
                } catch (Exception error) {
                    alert = new Alert("Error Writing", error.toString(), null, AlertType.WARNING);
                    alert.setTimeout(Alert.FOREVER);
                    display.setCurrent(alert);
                }
            }
    
          
            if (c == cmdEdit) {
                int index = 1 + list.getSelectedIndex();
                try {
                    formEdit = new Form("Edit Data Karyawan");
                    formEdit.addCommand(cmdBack);
                    formEdit.addCommand(cmdUbah);
                    formEdit.setTicker(tik);
                    formEdit.setCommandListener(this);
                    byte[] byteInputData = new byte[300];
                    String inputNama, inputNIK, inputJabatan, inputGaji = null;
                    ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData);
                    DataInputStream inputDataStream = new DataInputStream(inputStream);
                    if (currentTask == 1) {
                        filter = new Penyaring(keyword);
                        recordEnumeration = recordstore.enumerateRecords(filter, null, false);
                    }
                    if (currentTask == 2) {
                        Pembanding comparator = new Pembanding();
                        recordEnumeration = recordstore.enumerateRecords(null, comparator, false);
                    }
                    for (int i = 1; i <= recordEnumeration.numRecords(); i++) {
                        int datapointer = recordEnumeration.nextRecordId();
                        if (i == index) {
                            recordstore.getRecord(datapointer, byteInputData, 0);
                            recID = datapointer;
                            inputNama = inputDataStream.readUTF();
                            inputNIK = inputDataStream.readUTF();
                            inputJabatan = inputDataStream.readUTF();
                            inputGaji = inputDataStream.readUTF();
                            txtRecNama = new TextField("Nama:", inputNama, 20, TextField.ANY);
                            txtRecNIK = new TextField("NIK:", inputNIK, 30, TextField.PHONENUMBER);
                            txtRecJabatan = new TextField("Jabatan:", inputJabatan, 20, TextField.ANY);
                            txtRecGaji = new TextField("Gaji:", inputGaji, 30, TextField.PHONENUMBER);
    
                            formEdit.append(txtRecNama);
                            formEdit.append(txtRecNIK);
                            formEdit.append(txtRecJabatan);
                            formEdit.append(txtRecGaji);
                            inputStream.reset();
                        }
                    }
                    display.setCurrent(formEdit);
                    inputStream.close();
                } catch (Exception error) {
                    alert = new Alert("Error Reading", error.toString(), null, AlertType.WARNING);
                    alert.setTimeout(Alert.FOREVER);
                    display.setCurrent(alert);
                }
            }
    
            if (c == cmdHapus) {
                int index = 1 + list.getSelectedIndex();
                try {
                    if (currentTask == 1) {
                        filter = new Penyaring(keyword);
                        recordEnumeration = recordstore.enumerateRecords(filter, null, false);
                    }
                    if (currentTask == 2) {
                        Pembanding comparator = new Pembanding();
                        recordEnumeration = recordstore.enumerateRecords(null, comparator, false);
                    }
                    for (int i = 1; i <= recordEnumeration.numRecords(); i++) {
                        int datapointer = recordEnumeration.nextRecordId();
                        if (i == index) {
                            recordstore.deleteRecord(datapointer);
                        }
                    }
                    display.setCurrent(formUtama);
                } catch (Exception error) {
                    alert = new Alert("Error Reading", error.toString(), null, AlertType.WARNING);
                    alert.setTimeout(Alert.FOREVER);
                    display.setCurrent(alert);
                }
            }
    
            if (c == cmdLihatData) {
                try {
                    list = new List("Nama-Nama Karyawan", List.IMPLICIT);
                    list.addCommand(cmdDataBaru);
                    list.addCommand(cmdFind);
                    list.addCommand(cmdCancel);
                    list.setTicker(tik);
                    list.setCommandListener(this);
                    currentTask = 2;
                    byte[] byteInputData = new byte[300];
                    String inputNama, inputNIK, inputJabatan, inputGaji = null;
                    ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData);
                    DataInputStream inputDataStream = new DataInputStream(inputStream);
                    Pembanding comparator = new Pembanding();
                    recordEnumeration = recordstore.enumerateRecords(null, comparator, false);
                    while (recordEnumeration.hasNextElement()) {
                        recordstore.getRecord(recordEnumeration.nextRecordId(), byteInputData, 0);
                        inputNama = inputDataStream.readUTF();
                        inputNIK = inputDataStream.readUTF();
                        inputJabatan = inputDataStream.readUTF();
                        inputGaji = inputDataStream.readUTF();
                        list.append("(+) "+ inputNama + "", null);
                        inputStream.reset();
                    }
                    display.setCurrent(list);
                    inputStream.close();
                } catch (Exception error) {
                    alert = new Alert("Error Reading", error.toString(), null, AlertType.WARNING);
                    alert.setTimeout(Alert.FOREVER);
                    display.setCurrent(alert);
                }
            }
    
          
            if (c == List.SELECT_COMMAND) {
                int index = 1 + list.getSelectedIndex();
                try {
                    formLihat = new Form("Rincian Data Karyawan ");
                    formLihat.addCommand(cmdBack);
                    formLihat.addCommand(cmdEdit);
                    formLihat.addCommand(cmdHapus);
                    formLihat.setTicker(tik);
                    formLihat.setCommandListener(this);
                    byte[] byteInputData = new byte[300];
                    String inputNama, inputNIK, inputJabatan, inputGaji = null;
                    ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData);
                    DataInputStream inputDataStream = new DataInputStream(inputStream);
                    if (currentTask == 1) {
                        filter = new Penyaring(keyword);
                        recordEnumeration = recordstore.enumerateRecords(filter, null, false);
                    }
                    if (currentTask == 2) {
                        Pembanding comparator = new Pembanding();
                        recordEnumeration = recordstore.enumerateRecords(null, comparator, false);
                    }
                    for (int i = 1; i <= recordEnumeration.numRecords(); i++) {
                        int datapointer = recordEnumeration.nextRecordId();
                        if (i == index) {
                            recordstore.getRecord(datapointer, byteInputData, 0);
                            recID = datapointer;
                            inputNama = inputDataStream.readUTF();
                            inputNIK = inputDataStream.readUTF();
                            inputJabatan = inputDataStream.readUTF();
                            inputGaji = inputDataStream.readUTF();
                            StringItem stringNama = new StringItem("Nama: ", inputNama, Item.PLAIN);
                            StringItem stringNIK = new StringItem("NIK: ", inputNIK, Item.PLAIN);
                            StringItem stringJabatan = new StringItem("Jabatan: ", inputJabatan, Item.PLAIN);
                            StringItem stringGaji = new StringItem("Gaji: ", inputGaji, Item.PLAIN);
                            formLihat.append(stringNama);
                            formLihat.append(stringNIK);
                            formLihat.append(stringJabatan);
                            formLihat.append(stringGaji);
                            inputStream.reset();
                        }
                    }
                    display.setCurrent(formLihat);
                    inputStream.close();
                } catch (Exception error) {
                    alert = new Alert("Error Reading", error.toString(), null, AlertType.WARNING);
                    alert.setTimeout(Alert.FOREVER);
                    display.setCurrent(alert);
                }
            }
    
            try {
                recordstore.closeRecordStore();
            } catch (Exception error) {
                alert = new Alert("Error Closing", error.toString(), null, AlertType.WARNING);
                alert.setTimeout(Alert.FOREVER);
                display.setCurrent(alert);
            }
        }
    } 


===================TERIMA KASIH SEMOGA BERMANFAAT=====================