Posts Tagged ‘Programming

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
    07

    USER CONTROL

    User Control adalah Control yang dibuat oleh user berdasarkan class System.Windows.Forms.UserControl. Seperti standart control, User Controls juga support properties, methods and events. User Control yang sudah dibuat bisa ditambahkan dalam form seperti control-control yang lain.

    Membuat User Control

    Untuk membuat user control select File->New->Project->Visual Basic Projects -> Windows Control Library from the templates and klik OK. Selain itu anda juga da[at menambahkan user control pada project dangan select Project->Add User Control. Gambar dibawah ini adalah dialog yang muncul untuk menambahkan user control pada project kita:

    create.gif

    Form yang akan muncul setelah kita klik OK adalah seperti dibawah ini, seperti form normal.

    form.gif

    Membuat user control dengan text box sederhana

    Tambahkan text box dan label pada form

    labeldantext.gif

    Dobel klik pada form dan tambahkan kode berikut pada even on load

    Public Property sanText() As String
    Get
    sanText = TextBox1.Text
    End Get
    Set(ByVal Value As String)
    TextBox1.Text = Value
    End Set
    End Property
    Public Property sanLbl() As String
    Get
    sanLbl = Label1.Text
    End Get
    Set(ByVal Value As String)
    Label1.Text = Value
    End Set
    End Property

    Setelah itu build dengan Build->Build Solution pada main menu untuk menghasilkan file .dl

    Untuk menambahkan user control yang sudah kita buat lakukan klik kanan pada tool box kemudian Customize Toolbox dapat dilihat pada gambar seperti dibawah ini :

    customize-tool.gif

    Klik pada customize toolbox maka akan muncul customize toolbox dialog seperti gambar dibawah ini

    dialog-component.gif

    Pilih komponen yang telah anda buat dan tambahkan ke dalam form anda.

    Kemudian anda dapat menambahkan kode program seperti control-control yang lainnya.

    Contoh :

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal_
    e As System.EventArgs) Handles Button1.Click
    MessageBox.Show(“TextBox” & UserControl11.sanText())
    MessageBox.Show(“Label1″ & UserControl11.sanLbl())
    End Sub

    14
    Nov
    07

    Exception

    Contoh 3 exception yang biasa digunakan dalam VB. Net

    OOP Object Oriented Programming 

    1. InvalidExpressionException fungsinya adalah untuk menangkap error expression dari  statement

    Contoh :

    Try

    conn.Close()

    Catch ex As InvalidExpressionException

    ‘statemen yang akan dilakukan

    End Try

    2. DivideByZeroException fungsinya adalah untuk menangkap error yang muncul dari suatu angka yang dibagi dengan angka 0

    Contoh :

    Try

    Dim a As Integer = 10

    Dim b As Integer = 0

    a = a / b

    Catch ex As DivideByZeroException

                ‘statemen yang akan dilakukan

    End Try

    2. OverflowException fungsinya adalah untuk menangkap error yang muncul dari statement yang menyebabkan suatu variable melebihi kapasitas dari tipe variable tersebut sepert Integer

    Contoh :

    Try

    Dim a As Integer = 2

    Do While a < 10

    ‘ code statement

    x -= 1

    Loop

    Catch ex As OverflowException

    ‘statemen yang akan dilakukan

    End Try

    14
    Nov
    07

    OOP Object Oriented Programming

    OOP Object Oriented Programming

    Object Oriented Programming adalah bahasa yang memiliki konsep objek seperti halnya objek didunia nyata.

    Dalam OOP kita mengenal Class

    Class adalah cetak biru (blue print) dari objek atau juga bisa disebut cetakan (template) dari beberapa objek yang memiliki kesamaan ciri dan sifat

    Langkah-langkah pembuatan Class

    1. Buka Project dalam Microsoft Visual Studio .NET

    2. Pada Project menu click Add Class

    add class

    3. pada kotak dialog nama, ketik nama class dan click open

     

    Class Name

    4. Kemudian akan muncul code editor dari statement class seperti dibahaw ini

    Public Class ClassName

    End Class

    5. Setelah membuat class baru anda dapat menambahkan data members pada class yang telah anda buat. Anda dapat menentukan level access dengan setting access modifier

    Contoh : Private price as double

    6. Anda da[at menambahkan method pada class.

    7. Jangan lupa membuat Contructor pada class. Constructor adalah method yang pertama kali dijalankan pada saat suatu object terbentuk.

    Contoh : Sub new ()

    Nama = “joni”

    End Sub

    8. Setelah itu anda dapat menambahkan property pada Class

    Contoh :

    Public Property Customer() As String

    Get

    Return CustomerName

    End Get

    Set(ByVal Value As String)

    CustomerName = Value

    End Set

    End Property

    9. Cara menginstankan Class dapat dilakukan seperti statement di bawah ini

    Dim xCustomer As New Customer




    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.