Archive for the 'J2ME' Category

12
Jun
09

URL ENCODE IN J2ME

This is example class of URL Encode
to encode string to valid URL

source from Nokir Forum

public static String urlEncode(String s) {
StringBuffer sbuf = new StringBuffer();
int len = s.length();
for (int i = 0; i < len; i++) {
int ch = s.charAt(i);
if (‘A’ <= ch && ch <= ‘Z’) { // ‘A’..’Z’
sbuf.append((char)ch);
} else if (‘a’ <= ch && ch <= ‘z’) { // ‘a’..’z’
sbuf.append((char)ch);
} else if (’0′ <= ch && ch <= ’9′) { // ’0′..’9′
sbuf.append((char)ch);
} else if (ch == ‘ ‘) { // space
sbuf.append(‘+’);
} else if (ch == ‘-’ || ch == ‘_’ // unreserved
|| ch == ‘.’ || ch == ‘!’
|| ch == ‘~’ || ch == ‘*’
|| ch == ‘\\’ || ch == ‘(‘
|| ch == ‘)’) {
sbuf.append((char)ch);
} else if (ch <= 0x007f) { // other ASCII
sbuf.append(hex[ch]);
} else if (ch <= 0x07FF) { // non-ASCII <= 0x7FF sbuf.append(hex[0xc0 | (ch >> 6)]);
sbuf.append(hex[0x80 | (ch & 0x3F)]);
} else { // 0x7FF < ch <= 0xFFFF sbuf.append(hex[0xe0 | (ch >> 12)]);
sbuf.append(hex[0x80 | ((ch >> 6) & 0x3F)]);
sbuf.append(hex[0x80 | (ch & 0x3F)]);
}
}
return sbuf.toString();
}

// Hex constants.
final static String[] hex = {
“%00″, “%01″, “%02″, “%03″, “%04″, “%05″, “%06″, “%07″,
“%08″, “%09″, “%0a”, “%0b”, “%0c”, “%0d”, “%0e”, “%0f”,
“%10″, “%11″, “%12″, “%13″, “%14″, “%15″, “%16″, “%17″,
“%18″, “%19″, “%1a”, “%1b”, “%1c”, “%1d”, “%1e”, “%1f”,
“%20″, “%21″, “%22″, “%23″, “%24″, “%25″, “%26″, “%27″,
“%28″, “%29″, “%2a”, “%2b”, “%2c”, “%2d”, “%2e”, “%2f”,
“%30″, “%31″, “%32″, “%33″, “%34″, “%35″, “%36″, “%37″,
“%38″, “%39″, “%3a”, “%3b”, “%3c”, “%3d”, “%3e”, “%3f”,
“%40″, “%41″, “%42″, “%43″, “%44″, “%45″, “%46″, “%47″,
“%48″, “%49″, “%4a”, “%4b”, “%4c”, “%4d”, “%4e”, “%4f”,
“%50″, “%51″, “%52″, “%53″, “%54″, “%55″, “%56″, “%57″,
“%58″, “%59″, “%5a”, “%5b”, “%5c”, “%5d”, “%5e”, “%5f”,
“%60″, “%61″, “%62″, “%63″, “%64″, “%65″, “%66″, “%67″,
“%68″, “%69″, “%6a”, “%6b”, “%6c”, “%6d”, “%6e”, “%6f”,
“%70″, “%71″, “%72″, “%73″, “%74″, “%75″, “%76″, “%77″,
“%78″, “%79″, “%7a”, “%7b”, “%7c”, “%7d”, “%7e”, “%7f”,
“%80″, “%81″, “%82″, “%83″, “%84″, “%85″, “%86″, “%87″,
“%88″, “%89″, “%8a”, “%8b”, “%8c”, “%8d”, “%8e”, “%8f”,
“%90″, “%91″, “%92″, “%93″, “%94″, “%95″, “%96″, “%97″,
“%98″, “%99″, “%9a”, “%9b”, “%9c”, “%9d”, “%9e”, “%9f”,
“%a0″, “%a1″, “%a2″, “%a3″, “%a4″, “%a5″, “%a6″, “%a7″,
“%a8″, “%a9″, “%aa”, “%ab”, “%ac”, “%ad”, “%ae”, “%af”,
“%b0″, “%b1″, “%b2″, “%b3″, “%b4″, “%b5″, “%b6″, “%b7″,
“%b8″, “%b9″, “%ba”, “%bb”, “%bc”, “%bd”, “%be”, “%bf”,
“%c0″, “%c1″, “%c2″, “%c3″, “%c4″, “%c5″, “%c6″, “%c7″,
“%c8″, “%c9″, “%ca”, “%cb”, “%cc”, “%cd”, “%ce”, “%cf”,
“%d0″, “%d1″, “%d2″, “%d3″, “%d4″, “%d5″, “%d6″, “%d7″,
“%d8″, “%d9″, “%da”, “%db”, “%dc”, “%dd”, “%de”, “%df”,
“%e0″, “%e1″, “%e2″, “%e3″, “%e4″, “%e5″, “%e6″, “%e7″,
“%e8″, “%e9″, “%ea”, “%eb”, “%ec”, “%ed”, “%ee”, “%ef”,
“%f0″, “%f1″, “%f2″, “%f3″, “%f4″, “%f5″, “%f6″, “%f7″,
“%f8″, “%f9″, “%fa”, “%fb”, “%fc”, “%fd”, “%fe”, “%ff”
};

03
Jun
09

j2me polish 2.1 already release

Dear J2ME Polish community members!

You receive this newsletter as a member of the J2ME Polish community. Please don’t response to this address directly. To unsubscribe from this mailinglist, please send a short note to announce-owner@list.j2mepolish.org

These are the latest news regarding J2ME Polish and Enough Software:

1.J2ME Polish 2.1. officially released
2.We are looking for mobile application developers to take over whole projects
3.Our forum needs your support
4.Keep us informed about your J2ME Polish projects
5.Meet us on upcoming events in Singapore, Zurich or Amsterdam

1. J2ME Polish 2.1. officially released
It´s done! The new version of our framework is now available for download now. As you might have read on our website, there are a lot of new features implemented:
Android Support: Just target Generic/Android or HTC/G1 for converting your application to Android.
BlackBerry Storm Support: Now supporting BB Storm out of the box. Just target BlackBerry/Storm or BlackBerry/4.7.
UI: CSS Animation Framework: you can now animation any CSS attribute and react to both UI events like show and to your own custom application specific events.
UI: Specify dimensions of UI components relative to their available size with percentage values, e.g. max-width: 75.5%;
UI: New TabbedPane screen allows you to bundle several screens together on a single TabbedPane.
UI: de.enough.polish.calendar.CalendarItem allows you to view and select dates
UI: Use our de.enough.polish.video.VideoContainer to play back video on MIDP and BlackBerry handsets.
UI: ScreenChangeAnimation make use of the repaint-previous-screen setting, in those cases only the internal frame of the screen is animated.
Logging: The new display log handler allows you to view log entries in realtime on top of your application.
Bluetooth: Use our de.enough.polish.bluetooth classes for streaming over a L2CAP bluetooth connection and detecting other Bluetooth devices
HtmlBrowser: Use our HttpBluetothProtocolHandler to browse webpages over a bluetooth connection.
HtmlBrowser: Use the GZipResourceProtocolHandler for accessing compressed pages.
HtmlBrowser: Runtime CSS support in our HtmlBrowser allows you to specify styles within your HTML code.
Virtual Devices: Added Generic/AnyMsaPhone and its cousins: Generic/AnyMsaPhone_240x320, Generic/AnyMsaPhone_320x240, Generic/AnyMsaPhone_352x416 for covering most popular devices that are compatible to the Mobile Service Architecture specification.

www.enough.de

info@enough.de

11
Dec
08

membuat Button dari StringItem di J2ME

hmmm ada pertanyaan lagi pas mo ngerjain TA
gmn ya bikin button pada form di Midlet

cari2 di example ternyata ketemu,lagi2 sederhana heheh ga sesusah yang dibayangkan karena API Midp 2.0 udah lumayan lenkap
sama kek ItemStateListener yg pernh aq tulis dulu
lagi2 di J2ME kebanyakan pake Interface
nah tryt ada interface untuk item command listener ItemCommandListener

nah drpd disimpen ndiri skr aq tulis deh disini
biasa langkah2 dulu hehehe
1. implemen dulu interface ItemCommandListener ke midlet

  • public class StringButton extends MIDlet implements ItemCommandListener {
    }
  • 2. pilih tipe StringItem menjadi BUTTON dan set default commandnya

  • item = new StringItem(“Button “, “Button”, Item.BUTTON);
    item.setDefaultCommand(CMD_OK);
    item.setItemCommandListener(this);
  • 3, dafultmethodnya harus ada

  • public void commandAction(Command c, Item item) {
    (c == CMD_OK) {
    String text = “tombol ok ditekan”;
    Alert alert = new Alert(“Action”, text, null, AlertType.INFO);
    display.setCurrent(alert);
    }
    }
  • contoh simple skrip lengkapnya dibawah ini


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

    public class StringButton extends MIDlet implements ItemCommandListener {
    private static final Command CMD_OK = new Command("Go", Command.ITEM, 1);
    private Display display;
    private Form mainForm;

    protected void startApp() {
    display = Display.getDisplay(this);

    mainForm = new Form("Button Demo");

    item = new StringItem("Button ", "Button", Item.BUTTON);
    item.setDefaultCommand(CMD_OK);
    item.setItemCommandListener(this);
    display.setCurrent(mainForm);
    }

    public void commandAction(Command c, Item item) {
    if (c == CMD_OK) {
    String text = "tekan tombol nie";
    Alert a = new Alert("Action", text, null, AlertType.INFO);
    display.setCurrent(a);
    }
    }

    public void commandAction(Command c, Displayable d) {
    destroyApp(false);
    notifyDestroyed();
    }

    protected void destroyApp(boolean unconditional) {
    }

    protected void pauseApp() {
    }
    }

    oke guys slamat mencoba
    smoga anda smakin suka dengan J2ME hehehe

    tunggu tulisan2 J2ME berikutx ya ntr mo bahas J2ME POLISH
    apaan tu?tgg ye… :D

    10
    Dec
    08

    Item Listener in J2ME

    dalam programming pasti dikenal istilah even handler atau listener kalau di JAVA, even adalah kapan program disuru melakukan sesuatu atas perintah user,misalnya
    onClick,button click,onChange n byk banget yang lainya yg tidak bisa aq sebutin 1 per 1 hehehe :D

    nah kalo di desktop atau web application pastinya aq da terbiasa banget menggunakanx waktu develope suatu aplikasi
    nah pertanyaanx gmn klo even atau listener pada mobile app dengan J2ME???
    aq mulai cari2 ttg ini krn brhubungan dengan TA ku yaitu Mobile Commerce with J2ME
    stlh googling akirx ketemu dah carax

    simple n mudah ternyata
    klo uda biasa coding pake Java pastix da tw donk Interface
    nah tryt di J2ME da Interface yg namax ItemStateListener

    1. langkah2 menggunakan ItemStateListener sebelumx qt mesti implement interface tersebut ke class Midlet qt seperti dibawah ini

  • public final class ContohListener extends MIDlet implements ItemStateListener
  • 2. nah setelah qt lakukan diatas set ItemStateListener pada display

  • setItemStateListener (this);
  • 3. default method harus ada dan method yg digunakan adalah
    public void itemStateChanged(Item item) throws

  • UnsupportedFieldException {
    if(item==e_gender) {
    int index = e_gender.getSelectedIndex ();
    System.out.println(“Error” + index);
    switch (index) {
    case 0:
    System.out.println(“Male”);
    break;
    case 1:
    System.out.println(“Female”);
    break;
    }
    }
    }
  • dan dibawah ini contoh code yang barusan aq bwt

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

    package main.app;
    import java.io.*;
    import java.util.*;
    import javax.microedition.io.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.pim.UnsupportedFieldException;

    /**
    *
    * @author harun
    */
    public class FrmRegistration extends Form implements CommandListener,ItemStateListener {
    private Display tampilanSebelumnya;
    private Displayable dpySebelumnya;
    private TextField txtSponsorName,txtName,txtAlamat,txtSponsor,txtTlp;
    private Command cmdTambah,cmdKembali;
    private DateField dob;

    private String user;
    private String password;
    private String caption;
    private String act;
    private String[] stringArray = { “M”, “F” };
    private ChoiceGroup e_gender;
    private Image im,im2;
    private StringItem space;

    public FrmRegistration(Display dpy, Displayable prev){
    super(“Form Registrasi”);

    tampilanSebelumnya = dpy;
    dpySebelumnya = prev;
    txtName = new TextField(“Nama:”,”",50,TextField.ANY);
    txtSponsor = new TextField(“ID Sponsor: “,”",8,TextField.NUMERIC);
    txtSponsorName = new TextField(“Nama Sponsor:”,”",50,TextField.ANY);
    txtAlamat = new TextField(“Alamat:”,”",50,TextField.ANY);
    txtTlp = new TextField(“Telepon: “,”",15,TextField.NUMERIC);
    caption = “Tambah”;
    e_gender = new ChoiceGroup(“Search By: “, ChoiceGroup.POPUP, stringArray,null);
    append(txtName);
    append(txtSponsor);
    append(txtSponsorName);
    append(e_gender);
    append(txtAlamat);
    append(txtTlp);

    cmdTambah = new Command(caption,Command.OK,1);
    cmdKembali = new Command(“Kembali”,Command.BACK,1);
    addCommand(cmdTambah);
    addCommand(cmdKembali);
    setCommandListener(this);
    setItemStateListener (this);
    space = new StringItem(“”,”");
    append(space);
    space.setLayout(Item.LAYOUT_CENTER);
    }

    public void commandAction(Command c,Displayable d){
    if(c==cmdKembali){
    tampilanSebelumnya.setCurrent(dpySebelumnya);
    }else if(c==cmdTambah){

    }
    }

    public void itemStateChanged(Item item) throws UnsupportedFieldException {
    if(item==e_gender) {
    int index = e_gender.getSelectedIndex ();
    switch (index) {
    case 0: txtSponsorName.setString(“Male”);
    break;
    case 1: txtSponsorName.setString(“Female”);
    break;
    }
    }
    }
    }

    oke slamat mencoba
    ada pertanyaan silakan comment….
    gud Luck :)




    Blog Stats

    • 8,705 hits

    Top Clicks

    free ms prita

     

    June 2012
    M T W T F S S
    « Jun    
     123
    45678910
    11121314151617
    18192021222324
    252627282930  

    Categories

    Join My Community at MyBloglog!

    Online Status

    Dukung Gerakan Ini

    Go Green Indonesia


    Greenpeace

    Join One Campaign

    Pages

    my twitter


    Follow

    Get every new post delivered to your Inbox.