Saturday, December 15, 2012

Script format_tanggal_indonesia.php

<?php
echo '<font face="Verdana, Arial, Helvetica, sans-serif" size="2">';
function tanggal_hari_ini(){
$hari=date(w,time());
$tanggal=date(d,time());
$bulan=date(m,time());
$tahun=date(Y,time());
switch ($hari) {
case 0: $hari="Minggu";
break;
case 1: $hari="Senin";
break;
case 2: $hari="Selasa";
break;
case 3: $hari="Rabu";
break;
case 4: $hari="Kamis";
break;
case 5: $hari="Jum'at";
break;
case 6: $hari="Sabtu";
break;
}
switch ($bulan) {
case 01: $bulan="Januari";
break;
case 02: $bulan="Februari";
break;
case 03: $bulan="Maret";
break;
case 04: $bulan="April";
break;
case 05: $bulan="Mei";
break;
case 06: $bulan="Juni";
break;
case 07: $bulan="Juli";
break;
case 08: $bulan="Agustus";
break;
case 09: $bulan="September";
break;
case 10: $bulan="Oktober";
break;
case 11: $bulan="November";
break;
case 12: $bulan="Desember";
break;
}
echo "<b>Format Tanggal Indonesia</b><br>Ini Hari $hari<br>Tanggal $tanggal $bulan $tahun";
}
tanggal_hari_ini();
?>



Script format_mata_uang.php

<font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<form method="post" action="format_mata_uang.php">
<b>Format Mata Uang</b><br />
<label>Input Jumlah Uang <input type="text" name="uang" />
</label>
<label>
<input type="submit" name="Submit" value="Proses" />
</label>
<br /><hr align="left" width="100%" />
Nilai Angka : <? echo "$uang"; ?>
<br />Hasil Format : <? print number_format($uang); ?>
</form>


Scrip Encode pada php

<? echo ("
<font face=\"Verdana\" size=\"2\">
<FORM>
<b>Isi nilai string yang akan diproses</b><p>
<INPUT TYPE=TEXT NAME=code VALUE=\"$code\">
<INPUT TYPE=SUBMIT NAME=action VALUE=\"Encode\">
<INPUT TYPE=SUBMIT NAME=action VALUE=\"Decode\">
</FORM><BR>
");
if($action == "Encode") {
echo "<B>Hasil:</FONT></B><BR>";
echo base64_encode($code);
} elseif($action == "Decode") {
echo "<B>Hasil:</FONT></B><BR>";
echo base64_decode($code);
} ?>


Scrip deteksi_browser.php

<?php
echo '<font face="verdana" size="2">';
$useragent = $_SERVER ['HTTP_USER_AGENT'];
echo ("<b>Deteksi Browser</b><br>
Browser yang Anda gunakan sekarang adalah :<br>
$useragent");
?>



Script Daftar_link.php

<font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<b>Daftar Alamat Situs</b> <a href="email_teman.php">
<img src="images/friend.gif" border="0"/></a>
<br>
- Maxikom <br>- Forum Maxikom <br>
- Blog Ruli<br>- Marping <br>
- Friendster

Friday, December 14, 2012

Script counter.php

<?php
function counter(){
if (isset($visitor)){
if ($visitor=="visited")
include("counter.txt");
} else {
$file=fopen("counter.txt","r+");
$nilai=fread($file,filesize("counter.txt"));
fclose($file);
$nilai += 1;
$file=fopen("counter.txt","w+");
fputs($file,$nilai);
fclose($file);
include("counter.txt");
}
}
?>

Sourcecode cetak halaman.php

<?php
echo '<font face="Verdana" size="6">
Contoh untuk cetek halaman dengan </font>
<font face="Verdana" size="6" color="#FF0000">PHP</font><br>';
echo '<font face="Verdana" size="2">
<A HREF="javascript:window.print()">
Klik di sini </A>untuk mencetak halaman</font>';
?>


Auto_redirect_url.php

<?php
$waktu="5";
echo ("<html>
<head>
       <META HTTP-EQUIV=\"Refresh\" CONTENT=\"$waktu; URL=http://www.maxikom.co.id\">
</head>
<body><font face=\"Verdana\" size=\"2\">
Halaman ini akan diredirect ke situs Maxikom dalam waktu $waktu detik<br>
Silahkan <a href=\"http://www.maxikom.co.id\">klik di sini</a> jika proses gagal.</font></body>
</html>");
?>


Sourcecode aktivasi.php

<form name="form1" method="post" action="aktifkan_account.php">
  <div align="center">
    <table width="35%" border="1">
      <tr>
        <td>Username</td>
        <td>:</td>
        <td><label>
          <input name="username" type="text" id="username" value="<? echo "$username"; ?>">
        </label></td>
      </tr>
      <tr>
        <td>Kode Aktivasi </td>
        <td><label>:</label></td>
        <td><input name="kode_aktivasi" type="text" id="kode_aktivasi" value="<? echo "$aktivasi"; ?>"></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><label>
          <input type="submit" name="Submit" value="Aktifkan">
          <input type="reset" name="Submit2" value="Batal">
        </label></td>
      </tr>
    </table>
  </div>
  </form>



Sourcecode aktifkan account pada PHP

<?php $link = mysql_connect("localhost", "root", "maxikom");
mysql_select_db("trikphp", $link);
$perintah = "UPDATE email_aktivasi SET cek_aktivasi='$kode_aktivasi' WHERE username='$username' and aktivasi='$kode_aktivasi'";
$hasil = mysql_query($perintah);
if ($hasil) {
echo "Keanggotaan Anda telah diaktifkan";
}else{
echo ("Username atau Kode Aktifasi salah.<br>
Coba lihat kembali email yang Anda terima");
}
?>

Thursday, December 13, 2012

Membuat layar splash pada JAVA (J2ME)


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

public class LayarSplash extends MIDlet
  implements CommandListener {
   
  private Display display;
  private Form form;
  private Image image;
  private Alert splash;

  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
 
  public LayarSplash() {
    display = Display.getDisplay(this);
   
    form = new Form("Demo Splash");
    image = null;
    try {
        image = Image.createImage("/icons/Duke.png");     
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
   
    splash = new Alert(null, "  Inisialisasi proses...",
                 image, null);
    splash.setTimeout(7000);
       
    form.addCommand(cmdKeluar);
    form.setCommandListener(this);   
  }
   
  public void startApp() {                
    display.setCurrent(splash, form);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    }   
  } 
}

Membuat telepon menjadi bergetar pada JAVA (J2ME)


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

public class DemoVibrate extends MIDlet
  implements CommandListener {
   
  private Display display;
  private Form form;
   
  private Command cmdKeluar, cmdGetar;
   
  public DemoVibrate() {
    display = Display.getDisplay(this);
      
    form = new Form("Demo Vibrate");
    StringItem isi = new StringItem(null,
      "Pilih menu Getar untuk menjadikan " +
      "telepon Anda bergetar...",
      Item.PLAIN);
    form.append(isi);
       
    cmdKeluar = new Command("Keluar", Command.EXIT, 1);
    form.addCommand(cmdKeluar);
       
    cmdGetar = new Command("Getar", Command.SCREEN, 1);
    form.addCommand(cmdGetar);
      
    form.setCommandListener(this);
  }
   
  public void startApp() {     
    display.setCurrent(form);
  }
   
  public void pauseApp() {       
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    } else {
      display.vibrate(3000);
    }
  }
}

Sourcecode menempatkan beberapa objek ChoiceGroup dalam satu form Pada JAVA (J2ME)


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

public class DemoChoiceGroup extends MIDlet
  implements CommandListener {
   
  private Display display;
  private Form form;
  private TextField nama;
  private ChoiceGroup jenisKelamin, hobi;
   
  private Command cmdKeluar, cmdTampilkan;
   
  public DemoChoiceGroup() {
    display = Display.getDisplay(this);
       
    form = new Form("Demo ChoiceGroup");
      
    cmdKeluar = new Command("Keluar", Command.EXIT, 1);
    form.addCommand(cmdKeluar);
       
    cmdTampilkan = new Command("Tampilkan", Command.SCREEN, 1);
    form.addCommand(cmdTampilkan);
      
    form.setCommandListener(this);
  }
   
  public void startApp() {
    nama = new TextField("Nama", null, 25, TextField.ANY);
    form.append(nama);
       
    String[] gender = {"Laki-laki","Perempuan"};
    jenisKelamin = new ChoiceGroup("Jenis Kelamin",
                       Choice.EXCLUSIVE, gender, null);
    form.append(jenisKelamin);
       
    String[] hobbies = {"Membaca", "Memancing",
                        "Berolahraga", "Bersepeda"};
    hobi = new ChoiceGroup("Hobi", Choice.MULTIPLE,
                        hobbies, null);
    form.append(hobi);
       
    display.setCurrent(form);
  }
   
  public void pauseApp() {     
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    } else {
      Form newForm = new Form("Hasil");
          
      StringItem siNama = new StringItem("Nama:\n",
                              nama.getString(), Item.PLAIN);
      newForm.append(siNama);
           
      StringItem siJenisKelamin =
        new StringItem("Jenis kelamin:\n",              
        jenisKelamin.getString(jenisKelamin.getSelectedIndex()),
        Item.PLAIN);
      newForm.append(siJenisKelamin);
           
      StringBuffer sb = new StringBuffer();
      for (int i=0; i<hobi.size(); i++) {
        if (hobi.isSelected(i)) {
          sb.append("- " + hobi.getString(i) + "\n");
        }
      }

      StringItem siHobi = new StringItem("Hobi:\n",
                                sb.toString(), Item.PLAIN);
      newForm.append(siHobi);
           
      display.setCurrent(newForm);
    }
  }
}

Membuat dan menampilkan objek Alert pada JAVA (J2ME)


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

public class DemoAlert extends MIDlet
  implements CommandListener {
   
  private Display display;
  private Form form;
  private Alert alert;
  private Command cmdKeluar;
  private Command cmdAlert;

  // constructor
  public DemoAlert() {

    display = Display.getDisplay(this);

    // membuat form
    form = new Form("Contoh Alert");

    // menambahkan teks ke dalam form
    form.append("Contoh teks di dalam form");

    // membuat dua buah Command, "Keluar" dan "Alert"
    cmdKeluar = new Command("Keluar", Command.EXIT, 1);
    cmdAlert  = new Command("Alert", Command.SCREEN, 2);

    // menambahkan Command ke dalam form
    form.addCommand(cmdKeluar);
    form.addCommand(cmdAlert);
    form.setCommandListener(this);
  }
   
  public void startApp() {
    display.setCurrent(form);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {   
  }

  // mendefinisikan method untuk membuat dan menampilkan Alert   
  private void showAlert() {
    String info = "Ini adalah contoh pesan " +
                  "atau informasi yang akan " +
                  "disampaikan kepada user";

    // membuat instance dari kelas Alert
    alert = new Alert("Informasi", info,
                      null, AlertType.ALARM);

    // mengeset berapa lama Alert akan ditampilkan
    alert.setTimeout(5000);  // 5000 berarti 5 detik

    // menampilkan Alert
    display.setCurrent(alert, form);
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(true);
      notifyDestroyed();
    } else if (c == cmdAlert) {
      // memanggil method showAlert()
      showAlert();
    }
  }   
}

Wednesday, December 12, 2012

Memperoleh ukuran layar ponsel pada JAVA (J2ME)


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

public class UkuranLayar extends MIDlet
  implements CommandListener {
   
  private Display display;
  private CurrentScreen canvas;

  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
 
  public UkuranLayar() {
    display = Display.getDisplay(this);   
    canvas = new CurrentScreen();
    canvas.addCommand(cmdKeluar);
    canvas.setCommandListener(this);
  }
   
  public void startApp() {
    display.setCurrent(canvas);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    }   
  }
 
  // inner class
  class CurrentScreen extends Canvas {
    public void paint(Graphics g) {
      int width = getWidth();
      int height = getHeight();
         
      // membersihkan layar dengan warna putih
      g.setColor(0xffffff);
      g.fillRect(0,0, width, height);
         
      Font font = g.getFont();
      int fontHeight = font.getHeight();
      String s = "Ukuran layar: " + width + " x " + height;
      int fontWidth = font.stringWidth(s);
        
      g.setColor(0,0,0);
      g.setFont(font);
      g.drawString(s, (width - fontWidth) / 2,
                      (height - fontHeight) / 2,
                       g.TOP | g.LEFT);
    }
  }
}

Menampilkan gambar dalam bentuk thumbnail pada JAVA (J2ME)


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

public class Thumbnail extends MIDlet
  implements CommandListener {
   
  private Display display;
  private Form form;
   
  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
   
  public Thumbnail() {
    display = Display.getDisplay(this);
  }
   
  public void startApp() {       
       
   form = new Form("Tampilan Thumbnail");
       
   Image image1 = null, image2 = null,
   image3 = null, image4 = null;

   try {
     image1 = Image.createImage("/icons/image1.jpg");
     image2 = Image.createImage("/icons/image2.jpg");
     image3 = Image.createImage("/icons/image3.jpg");
     image4 = Image.createImage("/icons/image4.jpg");
   } catch (IOException ioe) {
     ioe.printStackTrace();
   }
               
   form.append(createPreview(image1));
   form.append(createPreview(image2));
   form.append(createPreview(image3));
   form.append(createPreview(image4));
               
   form.addCommand(cmdKeluar);
   form.setCommandListener(this);       

   display.setCurrent(form);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    }
  }
      
  public static Image createPreview (Image image) {
    int sw = image.getWidth();
    int sh = image.getHeight();

    int pw = 82;
    int ph = pw * sh / sw;

    Image temp = Image.createImage(pw, ph);
    Graphics g = temp.getGraphics();

    for (int y = 0; y < ph; y++) {
      for (int x = 0; x < pw; x++) {
         g.setClip(x, y, 1, 1);
         int dx = x * sw / pw;
         int dy = y * sh / ph;
         g.drawImage(image, x - dx, y - dy,
         Graphics.LEFT | Graphics.TOP);
      }
    }

    Image preview = Image.createImage(temp);
    return preview;
  }       
}

Membangkitkan suara untuk objek Alert pada JAVA (J2ME)


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

public class SuaraAlert extends MIDlet
  implements CommandListener {
   
  private Display display;
  private List list;
  
  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
  private final Command cmdOK =
    new Command("OK", Command.SCREEN, 1);
 
  public SuaraAlert() {
    display = Display.getDisplay(this);   

    list = new List("Tipe Alert", Choice.EXCLUSIVE);
    list.append("Info", null);
    list.append("Warning", null);
    list.append("Error", null);
    list.append("Confirmation", null);
    list.append("Alarm", null);
   
    list.addCommand(cmdOK);
    list.addCommand(cmdKeluar);
    list.setCommandListener(this);
  }
   
  public void startApp() {   
    display.setCurrent(list);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    } else if (c == cmdOK) {       
      switch (list.getSelectedIndex()) {
        case 0: {
          displayAlert("Tipe INFO", AlertType.INFO);
          break;
        }
        case 1: {
          displayAlert("Tipe WARNING", AlertType.WARNING);
          break;
        }
        case 2: {
          displayAlert("Tipe ERROR", AlertType.ERROR); break;
        }
        case 3: {
          displayAlert("Tipe CONFIRMATION",
                        AlertType.CONFIRMATION);
          break;
        }
        case 4: {
          displayAlert("Tipe ALARM", AlertType.ALARM);
          break;
        }
      }
    } 
  }
 
  public void displayAlert(String text, AlertType type) {
    Alert alert =  new Alert("Suara dalam Alert", text,
                              null, type);
    display.setCurrent(alert);
    type.playSound(display);
  }   
}

Menyimpan/mengambil gambar ke/dari record store pada JAVA (J2ME)


import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.IOException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import javax.microedition.rms.InvalidRecordIDException;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreNotFoundException;
import javax.microedition.rms.RecordStoreNotOpenException;

public class SimpanAmbilGambar extends MIDlet
  implements CommandListener {
   
  private Display display;
  private Form formUtama;
  private RecordStore rs = null;
  private Image image = null;
 
  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
  private final Command cmdKembali =
    new Command("Kembali", Command.BACK, 1);
  private final Command cmdSimpan =
    new Command("Simpan", Command.SCREEN, 1);
  private final Command cmdBuka =
    new Command("Buka", Command.SCREEN, 1);
 
  public SimpanAmbilGambar() {
    display = Display.getDisplay(this);
   
    try {
      rs= RecordStore.openRecordStore("DBGambar", true);
    } catch (RecordStoreException rse) {
      rse.printStackTrace();
    }
   
    formUtama = new Form("Menyimpan Gambar");
   
    try {
      image = Image.createImage("Java.png");
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }
    formUtama.append(image);           
   
    formUtama.addCommand(cmdKeluar);
    formUtama.addCommand(cmdSimpan);
    formUtama.addCommand(cmdBuka);
    formUtama.setCommandListener(this);
  }
   
  public void startApp() {
    display.setCurrent(formUtama);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    } else if (c == cmdKembali) {
      display.setCurrent(formUtama);
    } else if (c == cmdSimpan) {
      byte[] b = null;
      Alert alert = new Alert("Simpan Gambar");
      alert.setTimeout(Alert.FOREVER);
     
      try {
        if (simpanGambar(image,
                         image.getWidth(), image.getHeight(),
                         "Java")) {
          alert.setString("Gambar telah tersimpan " +
                          "di dalam record store");
        } else {
          alert.setString("Gambar gagal disimpan " +
                          "ke dalam record store");
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
     
      alert.addCommand(cmdKembali);
      alert.setCommandListener(this);
      display.setCurrent(alert, formUtama);

    } else if (c == cmdBuka) {
      Form formGambar = new Form("Gambar dari Record Store");
     
      Image img =
        ambilGambar(image.getWidth(), image.getHeight());
     
      if (img != null) {
        Image newImage = Image.createImage(img);
        formGambar.append(newImage);
      }
     
      formGambar.addCommand(cmdKembali);
      formGambar.setCommandListener(this);
      display.setCurrent(formGambar);
    }
  }          
 
  public boolean simpanGambar(Image img, int lebar,
                              int tinggi, String nama) {
    if (img == null || lebar < 0 ||
        tinggi < 0 || nama == null) {
      throw new IllegalArgumentException("Terjadi kesalahan " +
                         "pengisian parameter");
    }
     
    int[] dataRGB = new int[lebar * tinggi];
     
    try {
      img.getRGB(dataRGB, 0, lebar, 0, 0, lebar, tinggi);
    } catch (Exception e) {
      return false;
    }
     
    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      DataOutputStream dos = new DataOutputStream(baos);
      dos.writeUTF(nama);
         
      for (int i=0; i<dataRGB.length; i++) {
        dos.writeInt(dataRGB[i]);
      }
         
      byte[] dataRecord = baos.toByteArray();
         
      rs.addRecord(dataRecord, 0, dataRecord.length);
    } catch (RecordStoreNotFoundException rsnfe) {
      return false;
    } catch (RecordStoreException rse) {
      return false;
    } catch (IOException ioe) {
      return false;
    }
     
    return true;
  }
 
  public Image ambilGambar(int lebar, int tinggi) {
    byte[] data = null;
    String nama = null;
    Image img = null;
    
    try {
      int jumlahRecord = rs.getNumRecords();
      for (int i=1; i < jumlahRecord + 1; i++) {
        if (rs.getRecord(i) != null) {
          data = rs.getRecord(i);
          ByteArrayInputStream bais =
            new ByteArrayInputStream(data);
          DataInputStream dis = new DataInputStream(bais);
          nama = dis.readUTF();
          int sisa = (data.length-nama.getBytes().length-2)/4;
                 
          int[] dataRGB = new int[sisa];
          for (int j=0; j<dataRGB.length; j++) {
            dataRGB[j] = dis.readInt();
          }
                 
          img = Image.createRGBImage(dataRGB, lebar,
                                     tinggi, false);
                 
          bais.reset();
          dis.close();
          dis = null;
        }
      }
    } catch (IOException ioe) {
      ioe.printStackTrace();
    } catch(InvalidRecordIDException irie) {
      irie.printStackTrace();
    } catch (RecordStoreNotOpenException rsnoe) {
      rsnoe.printStackTrace();
    } catch (RecordStoreException rse) {
      rse.printStackTrace();
    }
    
    return img;
  }
 
}

Memperoleh nilai properti sistem pada JAVA (J2ME)


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

public class PropertiSistem extends MIDlet
  implements CommandListener {
   
  private Display display;
  private Form form;
  private StringBuffer sb;

  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
 
  public PropertiSistem() {
    display = Display.getDisplay(this);
   
    form = new Form("Properti Sistem");
       
    form.addCommand(cmdKeluar);
    form.setCommandListener(this);   
  }
   
  public void startApp() {
    sb = getSystemProperties();
    StringItem si = new StringItem(null, sb.toString());
    form.append(si);
    display.setCurrent(form);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    }   
  }
 
  private StringBuffer getSystemProperties() {
    StringBuffer temp = new StringBuffer();
    temp.append("Versi JTWI: " +
        System.getProperty("microedition.jtwi.version"));
    temp.append("\nKonfigurasi: " +
        System.getProperty("microedition.configuration"));
    temp.append("\nProfil: " +
        System.getProperty("microedition.profiles"));
    temp.append("\nLokal: " +
        System.getProperty("microedition.locale"));
    temp.append("\nPlatform: " +
        System.getProperty("microedition.platform"));
    temp.append("\nModel ponsel: " +
        System.getProperty("device.model"));
    temp.append("\nVersi Software: " +
        System.getProperty("software.version"));
    temp.append("\nEncoding: " +
        System.getProperty("microedition.encoding"));
    temp.append("\nPort Komunikasi: " +
        System.getProperty("microedition.commports"));
    return temp;
  }
}

Tuesday, December 11, 2012

Memperoleh nilai properti MIDlet pada JAVA (J2ME)


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

public class PropertiMIDlet extends MIDlet
  implements CommandListener {
   
  private Display display;
  private Form form;
  private StringBuffer sb;

  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
 
  public PropertiMIDlet() {
    display = Display.getDisplay(this);
   
    form = new Form("Properti MIDlet");
       
    form.addCommand(cmdKeluar);
    form.setCommandListener(this);   
  }
   
  public void startApp() {
    sb = getAppProperties();
    StringItem si = new StringItem(null, sb.toString());
    form.append(si);
    display.setCurrent(form);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    }   
  }
 
  private StringBuffer getAppProperties() {
    StringBuffer temp = new StringBuffer();
    temp.append("Nama MIDlet: " +
        getAppProperty("MIDlet-Name"));
    temp.append("\nVersi: " +
        getAppProperty("MIDlet-Version"));
    temp.append("\nVendor: " +
        getAppProperty("MIDlet-Vendor"));
    temp.append("\nUkuran: " +
        getAppProperty("MIDlet-Jar-Size"));
    temp.append("\nURL: " +
        getAppProperty("MIDlet-Jar-URL"));
    return temp;
  }
}

Soucecode memperbesar ukuran gambar pada JAVA (J2ME)



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

public class PerbesarGambar extends MIDlet
  implements CommandListener {
   
  private Display display;
  private Form form;
  private Image image;

  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
  private final Command cmdPerbesar =
    new Command("Perbesar", Command.SCREEN, 1);
 
  public PerbesarGambar() {
    display = Display.getDisplay(this);   

    form = new Form("Memperbesar Gambar"); 
   
    form.addCommand(cmdPerbesar);
    form.addCommand(cmdKeluar);
    form.setCommandListener(this);
  }
   
  public void startApp() {
    image = null;
    try {
        image = Image.createImage("/image5.jpg");
    } catch(IOException ioe) {
        ioe.printStackTrace();
    }
    form.append(image);
    display.setCurrent(form);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    } else if (c == cmdPerbesar) {       
      form.deleteAll();
      image = perbesarGambar(image);
      form.append(image);
      display.setCurrent(form);
    } 
  }
 
  public Image perbesarGambar(Image img) {
    Image imgOutput = null;
   
    int[] rgbOutput = null;
    Graphics g = null;
    int lebar = 0;
    int tinggi = 0;
   
    try {       
      lebar  =  img.getWidth();
      tinggi = img.getHeight();       
      imgOutput  = Image.createImage(lebar << 1, tinggi << 1);
       
      int rgbInput[] = new int[lebar * tinggi];
      rgbOutput = new int[(lebar << 1) * (tinggi << 1)];
       
      img.getRGB(rgbInput, 0, lebar, 0, 0, lebar, tinggi);
       
      int i,j,k;
      k=0;
      for(i=0; i<(tinggi << 1); i+=2) {
        for(j=0; j<(lebar << 1); j+=2) {
          rgbOutput[i* (lebar << 1) + j]      = rgbInput[k] ;
          rgbOutput[(i+1) * (lebar << 1) + j] = rgbInput[k];
          rgbOutput[i* (lebar << 1) + j+1]    = rgbInput[k];
          rgbOutput[(i+1)*(lebar << 1) + j+1] = rgbInput[k];
          k++;
        }
      }       
      g = imgOutput.getGraphics();
    } catch(Exception e){}
   
    return imgOutput.createRGBImage(rgbOutput,
                     lebar << 1,
                     tinggi << 1,
                     true);
  }   
}

Membuat help dalam MIDlet pada JAVA (J2ME)


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

public class OnlineHelp extends MIDlet
  implements CommandListener {
   
  private Display display;
  private List list;
  private Form form;
 
  private String help = "Ini adalah contoh teks panjang " +
          "yang akan digunakan " +
          "sebagai teks bantuan/help " +
          "dalam penggunaan aplikasi.";
  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
 
  private final Command cmdHelp =
    new Command("Help", Command.HELP, 1);
 
  private final Command cmdKembali =
    new Command("Kembali", Command.BACK, 1);
 
  public OnlineHelp() {
    display = Display.getDisplay(this);
   
    list = new List("Bahasa Favorit", Choice.MULTIPLE);
    list.append("Java", null);
    list.append("C", null);
    list.append("C++", null);
    list.append("Pascal", null);
       
    list.addCommand(cmdKeluar);
    list.addCommand(cmdHelp);
    list.setCommandListener(this);   
  }
   
  public void startApp() {
    display.setCurrent(list);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    } else if (c == cmdHelp) {
      form = new Form("Online-Help");
      form.append(help);
      form.addCommand(cmdKembali);
      form.setCommandListener(this);     
      display.setCurrent(form);
    } else {
      display.setCurrent(list); 
    }
  }
}

Monday, December 10, 2012

Membuat layar splash pada JAVA (J2ME)


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

public class LayarSplash extends MIDlet
  implements CommandListener {
   
  private Display display;
  private Form form;
  private Image image;
  private Alert splash;

  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
 
  public LayarSplash() {
    display = Display.getDisplay(this);
   
    form = new Form("Demo Splash");
    image = null;
    try {
        image = Image.createImage("/icons/Duke.png");     
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
   
    splash = new Alert(null, "  Inisialisasi proses...",
                 image, null);
    splash.setTimeout(7000);
       
    form.addCommand(cmdKeluar);
    form.setCommandListener(this);   
  }
   
  public void startApp() {                
    display.setCurrent(splash, form);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    }   
  } 
}

Memperoleh jumlah memori yang tersedia pada JAVA (J2ME)


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

public class JumlahMemori extends MIDlet
  implements CommandListener {
   
  private Display display;
  private Form form;

  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
 
  public JumlahMemori() {
    display = Display.getDisplay(this);
   
    form = new Form("Jumlah Memori");
       
    form.addCommand(cmdKeluar);
    form.setCommandListener(this);   
  }   

  public void startApp() {
    Runtime runtime = Runtime.getRuntime();
    runtime.gc();
    long total = runtime.totalMemory();
    long bebas = runtime.freeMemory();
   
    StringBuffer sb = new StringBuffer();
    sb.append("Memori total: " + total + " byte\n");
    sb.append("Memori bebas: " + bebas + " byte");      
   
    form.append(sb.toString());
    display.setCurrent(form);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    }   
  }   
}

Menggambar teks di atas canvas pada JAVA (J2ME)


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

public class GambarTeks extends MIDlet
  implements CommandListener {
   
  private Display display;
  private TextCanvas canvas;
   
  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
 
  public GambarTeks() {
    display = Display.getDisplay(this);
           
    canvas = new TextCanvas(this);
   
    canvas.addCommand(cmdKeluar);
    canvas.setCommandListener(this);   
  }
   
  public void startApp() {
    display.setCurrent(canvas);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    }
  }
 
  class TextCanvas extends Canvas {
     
    private GambarTeks midlet;
           
    public TextCanvas(GambarTeks midlet) {
      this.midlet = midlet;
    }
     
    public void paint(Graphics g) {
      g.setColor(255, 255, 255);
      g.fillRect(0, 0, getWidth(), getHeight());
      g.setColor(255, 0, 0);
      Font font = Font.getFont(Font.FACE_PROPORTIONAL,
                    Font.STYLE_BOLD | Font.STYLE_UNDERLINED,
                    Font.SIZE_MEDIUM);
      g.setFont(font);
      g.drawString("Teks di dalam Canvas", 0, 0, g.LEFT | g.TOP);
    }          
  } 
}

Menempatkan gambar di atas objek Canvas, pada JAVA (J2ME)



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

public class GambarDalamCanvas extends MIDlet
  implements CommandListener {
   
  private Display display;
  private CanvasGambar canvas;
 
  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
 
  public GambarDalamCanvas() {
    display = Display.getDisplay(this);
    canvas = new CanvasGambar(this);
    canvas.addCommand(cmdKeluar);
    canvas.setCommandListener(this);
  }
   
  public void startApp() {
    display.setCurrent(canvas);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    }
  }          
 
  //inner class
  class CanvasGambar extends Canvas {
     
    private GambarDalamCanvas midlet;
    private Image image = null;
     
    public CanvasGambar(GambarDalamCanvas midlet) {
         
      this.midlet = midlet;
         
      try {
        image = Image.createImage("Java.png");
      } catch (IOException ioe) {
        ioe.printStackTrace();
      }
    }
     
    public void paint(Graphics g) {
      g.setColor(255, 255, 255);
      g.fillRect(0, 0, getWidth(), getHeight());
      g.setColor(0, 0, 255);
      g.drawString("Contoh gambar dalam canvas", 3, 0,
                   g.LEFT | g.TOP);
      g.drawImage(image, 3, 20, g.LEFT | g.TOP);
    }
  };
 
}

Membuat sourcecode telepon menjadi bergetar, pada JAVA (J2ME)



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

public class DemoVibrate extends MIDlet
  implements CommandListener {
   
  private Display display;
  private Form form;
   
  private Command cmdKeluar, cmdGetar;
   
  public DemoVibrate() {
    display = Display.getDisplay(this);
      
    form = new Form("Demo Vibrate");
    StringItem isi = new StringItem(null,
      "Pilih menu Getar untuk menjadikan " +
      "telepon Anda bergetar...",
      Item.PLAIN);
    form.append(isi);
       
    cmdKeluar = new Command("Keluar", Command.EXIT, 1);
    form.addCommand(cmdKeluar);
       
    cmdGetar = new Command("Getar", Command.SCREEN, 1);
    form.addCommand(cmdGetar);
      
    form.setCommandListener(this);
  }
   
  public void startApp() {     
    display.setCurrent(form);
  }
   
  public void pauseApp() {       
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    } else {
      display.vibrate(3000);
    }
  }
}

Menempatkan beberapa objek ChoiceGroup dalam satu form, pada JAVA (J2ME)


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

public class DemoChoiceGroup extends MIDlet
  implements CommandListener {
   
  private Display display;
  private Form form;
  private TextField nama;
  private ChoiceGroup jenisKelamin, hobi;
   
  private Command cmdKeluar, cmdTampilkan;
   
  public DemoChoiceGroup() {
    display = Display.getDisplay(this);
       
    form = new Form("Demo ChoiceGroup");
      
    cmdKeluar = new Command("Keluar", Command.EXIT, 1);
    form.addCommand(cmdKeluar);
       
    cmdTampilkan = new Command("Tampilkan", Command.SCREEN, 1);
    form.addCommand(cmdTampilkan);
      
    form.setCommandListener(this);
  }
   
  public void startApp() {
    nama = new TextField("Nama", null, 25, TextField.ANY);
    form.append(nama);
       
    String[] gender = {"Laki-laki","Perempuan"};
    jenisKelamin = new ChoiceGroup("Jenis Kelamin",
                       Choice.EXCLUSIVE, gender, null);
    form.append(jenisKelamin);
       
    String[] hobbies = {"Membaca", "Memancing",
                        "Berolahraga", "Bersepeda"};
    hobi = new ChoiceGroup("Hobi", Choice.MULTIPLE,
                        hobbies, null);
    form.append(hobi);
       
    display.setCurrent(form);
  }
   
  public void pauseApp() {     
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    } else {
      Form newForm = new Form("Hasil");
          
      StringItem siNama = new StringItem("Nama:\n",
                              nama.getString(), Item.PLAIN);
      newForm.append(siNama);
           
      StringItem siJenisKelamin =
        new StringItem("Jenis kelamin:\n",              
        jenisKelamin.getString(jenisKelamin.getSelectedIndex()),
        Item.PLAIN);
      newForm.append(siJenisKelamin);
           
      StringBuffer sb = new StringBuffer();
      for (int i=0; i<hobi.size(); i++) {
        if (hobi.isSelected(i)) {
          sb.append("- " + hobi.getString(i) + "\n");
        }
      }

      StringItem siHobi = new StringItem("Hobi:\n",
                                sb.toString(), Item.PLAIN);
      newForm.append(siHobi);
           
      display.setCurrent(newForm);
    }
  }
}

Source code menggambar bentuk geometri di dalam objek Canvasn, pada JAVA (J2ME)


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

public class BentukGeometri extends MIDlet
  implements CommandListener {
   
  private Display display;
  private List list;
  private Canvas canvas; 
  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
  private final Command cmdOK =
    new Command("OK", Command.OK, 1);
  private final Command cmdKembali =
    new Command("Kembali", Command.BACK, 1);
 
  public BentukGeometri() {
    display = Display.getDisplay(this);
    list = new List("Bentuk Geometri", Choice.EXCLUSIVE);
    list.append("Kotak", null);
    list.append("Lingkaran", null);
    list.addCommand(cmdKeluar);
    list.addCommand(cmdOK);
    list.setCommandListener(this);
  }
   
  public void startApp() {
    display.setCurrent(list);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    } else if (c == cmdKembali) {
      display.setCurrent(list);
    } else {
      switch (list.getSelectedIndex()) {
        case 0: {
          canvas = (Kotak) (new Kotak(this));
          break;   
        }
        case 1: {
          canvas = (Lingkaran) (new Lingkaran(this));
          break;     
        }
      }
      canvas.addCommand(cmdKembali);
      canvas.setCommandListener(this);
      display.setCurrent(canvas);
    }
  }          
   
  class Segiempat extends Canvas {     
    private BentukGeometri midlet;
     
    public Segiempat(BentukGeometri midlet) {        
      this.midlet = midlet;         
    }
     
    public void paint(Graphics g) {
      g.setColor(255, 255, 255);
      g.fillRect(0, 0, getWidth(), getHeight());
      g.setColor(0, 0, 0);
      g.drawRect(55, 55, 60, 60);
      g.setColor(255, 0, 0);
      g.fillRect(56, 56, 59, 59);
    }
  };
 
  class Lingkaran extends Canvas {
    private BentukGeometri midlet;
     
    public Lingkaran(BentukGeometri midlet) {        
      this.midlet = midlet;         
    }
     
    public void paint(Graphics g) {
      g.setColor(255, 255, 255);
      g.fillRect(0, 0, getWidth(), getHeight());
      g.setColor(255, 0, 0);     
      g.fillArc(55, 55, 60, 60, 0, 360);
    } 
  }; 
}

Mengatur posisi gambar yang ditampilkan, pada JAVA (J2ME)


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

public class AturLayoutGambar extends MIDlet
  implements CommandListener {
   
  private Display display;
  private List list;
  private PosisiGambar form;
 
  private String title = null;

  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
 
  private final Command cmdOK =
    new Command("OK", Command.OK, 1);
 
  public AturLayoutGambar() {
    display = Display.getDisplay(this);
   
    list = new List("Posisi Gambar", Choice.EXCLUSIVE);
    list.append("Kiri", null);
    list.append("Tengah", null);
    list.append("Kanan", null);
       
    list.addCommand(cmdKeluar);
    list.addCommand(cmdOK);
    list.setCommandListener(this);   
  }
   
  public void startApp() {
    display.setCurrent(list);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    } else if (c == cmdOK) {
      form = null;
      switch (list.getSelectedIndex()) {
        case 0: {
          form = new PosisiGambar(this, display,"LAYOUT_LEFT",
                   ImageItem.LAYOUT_LEFT);
          break;
        }
        case 1: {
          form = new PosisiGambar(this, display,"LAYOUT_CENTER",
                   ImageItem.LAYOUT_CENTER);   
          break;
        }
        case 2: {
          form = new PosisiGambar(this, display,"LAYOUT_RIGHT",
                   ImageItem.LAYOUT_RIGHT);   
          break;
        }
      }
      display.setCurrent(form);
    }
  }
 
  class PosisiGambar extends Form
    implements CommandListener {
    private AturLayoutGambar midlet;
    private Display display;
    private Image image;
   
    private final Command cmdKembali =
      new Command("Kembali", Command.BACK, 1);  
      
    public PosisiGambar(StudiKasus midlet, Display display,
      String title, int posisi) {
      super(title);
      this.midlet = midlet;
      this.display = display;
      image = null;
      try {
          image = Image.createImage("Java.png");
      } catch (IOException ioe) {
          ioe.printStackTrace();
      }
      ImageItem ii = new ImageItem(null, image, posisi, null);
      append(ii);
      addCommand(cmdKembali);
      setCommandListener(this);
      display.setCurrent(this);
    }
   
    public void commandAction(Command c, Displayable s) {
      if (c == cmdKembali) {
        display.setCurrent(midlet.list);
      }
    }   
  } 
}

Friday, December 7, 2012

Membuat Video Player sederhana, pada JAVA (J2ME)

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.VideoControl;
import java.io.InputStream;

public class VideoPlayer extends MIDlet
  implements CommandListener, Runnable, PlayerListener {
   
  private Display display;
  private Form form;
  private Thread thread;

  private Player player;
  private VideoControl videocontrol;

  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
  private final Command cmdMainkan =
    new Command("Mainkan", Command.SCREEN, 1);
  private final Command cmdBerhenti =
    new Command("Berhenti", Command.OK, 1);
 
  public VideoPlayer() {
    display = Display.getDisplay(this);
  }
   
  public void startApp() {
    form = new Form("Video Player");
    form.addCommand(cmdKeluar);
    form.addCommand(cmdMainkan);
    form.setCommandListener(this);
    display.setCurrent(form);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    } else if (c == cmdMainkan) {
      form.deleteAll();
      thread = new Thread(this);
      thread.start();
      form.removeCommand(cmdMainkan);
      form.removeCommand(cmdKeluar);
      form.addCommand(cmdBerhenti);
    } else if (c == cmdBerhenti) {
      try {
        player.stop();
        stopVideo();
      } catch (MediaException me) {
          me.printStackTrace();
      }
    }
  }          
 
  public void run() {
    try {
      InputStream is =
        getClass().getResourceAsStream("Video.3gp");
      player = Manager.createPlayer(is, "video/3gpp");
      player.addPlayerListener(this);
      player.realize();
     
      // mendapatkan kontrol video
      videocontrol =
        (VideoControl) player.getControl("VideoControl");
     
      // mendapatkan GUI untuk memainkan video
      Item videoItem = (Item) videocontrol.initDisplayMode(
        VideoControl.USE_GUI_PRIMITIVE, null);
     
      // memasukkan item yang didapat ke dalam form
      form.append(videoItem);
     
      // menjalankan video
      player.start();
     
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 
  public void stopVideo() {
    try {
      player.deallocate();
      player.close();
      player = null;
      thread = null;
      form.removeCommand(cmdBerhenti);
      form.addCommand(cmdMainkan);
      form.addCommand(cmdKeluar);
    } catch (Exception e) {
      e.printStackTrace(); 
    }
  }
 
  public void playerUpdate(Player player,
                           String event, Object data) {
    if (event.equals(STOPPED) ||
      event.equals(STOPPED_AT_TIME) ||
      event.equals(ERROR) ||
      event.equals(END_OF_MEDIA)) {     
      stopVideo();
    }
  }
 
}

Memperoleh tipe media dan protokol yang didukung, pada JAVA ( J2ME )

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

public class TipeMediaProtokol extends MIDlet
  implements CommandListener {
   
  private Display display;
  private Form form;
  private StringBuffer sb;
  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
 
  public TipeMediaProtokol() {
    display = Display.getDisplay(this);
   
    form = new Form("Tipe Media & Protokol");
       
    form.addCommand(cmdKeluar);
    form.setCommandListener(this);   
  }
   
  public void startApp() {
    sb = getMediaContentsAndProtocols();
    StringItem si = new StringItem(null, sb.toString());
    form.append(si);
    display.setCurrent(form);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    }   
  }
 
  private StringBuffer getMediaContentsAndProtocols() {
    StringBuffer temp = new StringBuffer();
    String[] tipeMedia = Manager.getSupportedContentTypes(null);
    for (int i=0; i<tipeMedia.length; i++) {
      String[] protokol =
        Manager.getSupportedProtocols(tipeMedia[i]);
      for (int j=0; j<protokol.length; j++) {
        temp.append(tipeMedia[i] + ":" + protokol[j] + "\n");
      }
    }
    return temp;
  }
}

Memperoleh properti sistem yang berkaitan dengan multimedia pada JAVA (J2ME)

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

public class SistemMedia extends MIDlet
  implements CommandListener {
   
  private Display display;
  private Form form;
  private StringBuffer sb;

  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
 
  public SistemMedia() {
    display = Display.getDisplay(this);
   
    form = new Form("Properti Sistem Media");
       
    form.addCommand(cmdKeluar);
    form.setCommandListener(this);   
  }
   
  public void startApp() {
    sb = getMediaProperties();
    StringItem si = new StringItem(null, sb.toString());
    form.append(si);
    display.setCurrent(form);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    }   
  }
 
  private StringBuffer getMediaProperties() {
    StringBuffer temp = new StringBuffer();
    temp.append("Mixing: " +
        System.getProperty("supports.mixing"));
    temp.append("\nAudio Capture: " +
        System.getProperty("supports.audio.capture"));
    temp.append("\nVideo Capture: " +
        System.getProperty("supports.video.capture"));
    temp.append("\nRecording: " +
        System.getProperty("supports.recording"));
    temp.append("\nAudio Encoding: " +
        System.getProperty("audio.encodings"));
    temp.append("\nVideo Encoding: " +
        System.getProperty("video.encodings"));
    temp.append("\nSnapshot: " +
        System.getProperty("video.snapshot.encodings"));
    temp.append("\nMedia Version: " +
        System.getProperty("microedition.media.version"));
    temp.append("\nStreamable content: " +
        System.getProperty("streamable.contents"));
    return temp;
  }
}

Membuat MIDI Player sederhana pada JAVA (J2ME)

import java.io.InputStream;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.VolumeControl;

public class MidiPlayer extends MIDlet
  implements CommandListener {
   
  private Display display;
  private List menu;
  private Form form;
  private Gauge volume;
 
  private Player player;
  private VolumeControl vc;

  private final Command cmdKeluar =
    new Command("Keluar", Command.EXIT, 1);
  private final Command cmdMainkan =
    new Command("Mainkan", Command.SCREEN, 1);
  private final Command cmdVolume =
    new Command("Set Volume", Command.SCREEN, 1);
  private final Command cmdOK =
    new Command("OK", Command.OK, 1);
  private final Command cmdBerhenti =
    new Command("Berhenti", Command.OK, 2);
 
  private final String[] FILE =
     {"File1.mid", "File2.mid", "File3.mid"};
 
  public MidiPlayer() {
    display = Display.getDisplay(this);
   
    menu = new List("MIDI Player", Choice.IMPLICIT, FILE, null);
          
    menu.addCommand(cmdKeluar);
    menu.addCommand(cmdMainkan);
    menu.addCommand(cmdVolume);
    menu.setCommandListener(this);   
  }
   
  public void startApp() {
    form = new Form("Volume");
    volume = new Gauge("Set Volume", true, 10, 5);
    display.setCurrent(menu);
  }
   
  public void pauseApp() {
  }
   
  public void destroyApp(boolean unconditional) {
  }
   
  public void commandAction(Command c, Displayable s) {
    if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
    } else if (c == cmdMainkan) {
      String namaFile = menu.getString(menu.getSelectedIndex());
      playMIDI(namaFile);
      menu.removeCommand(cmdMainkan);
      menu.removeCommand(cmdKeluar);
      menu.removeCommand(cmdVolume);
      menu.addCommand(cmdBerhenti);
    } else if (c == cmdBerhenti) {
      stopMIDI();
    } else if (c == cmdOK) {
      display.setCurrent(menu);
    } else {
      form.append(volume);
      form.addCommand(cmdOK);
      form.setCommandListener(this);
      display.setCurrent(form);
    }
  }
 
  public void playMIDI(String namaFile) {
    try {
      InputStream is = getClass().getResourceAsStream(namaFile);
      player = Manager.createPlayer(is, "audio/midi");
      player.addPlayerListener(new StopListener(this));
      player.realize();
      vc = (VolumeControl) player.getControl("VolumeControl");
      vc.setLevel(volume.getValue() * 10);
      player.start();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 
  public void stopMIDI() {
    try {
      player.stop();
      player.deallocate();
      player.close();
      player = null;
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 
  // inner class
  class StopListener implements PlayerListener {
     
    private MidiPlayer midlet;
     
    public StopListener(MidiPlayer midlet) {
      this.midlet = midlet;
    }
     
    public void playerUpdate(Player player,
                             String event, Object data) {
      try {
        if (event.equals(STOPPED) ||
          event.equals(STOPPED_AT_TIME) ||
          event.equals(ERROR) ||
          event.equals(END_OF_MEDIA)) {
          player.deallocate();
          player.close();
          player = null;
          midlet.menu.removeCommand(midlet.cmdBerhenti);
          midlet.menu.addCommand(midlet.cmdMainkan);
          midlet.menu.addCommand(midlet.cmdVolume);
          midlet.menu.addCommand(midlet.cmdKeluar);
        } else if (event.equals(DEVICE_UNAVAILABLE)) {
          player.stop();
        } else if (event.equals(DEVICE_AVAILABLE)) {
          player.start();
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }         
  }
 
}