Assalamu'alaikum Wr.Wb
Kali ini saya akan memposting contoh sebuah fungsi string item di dalam J2ME, String Item itu merupakan class turunan dari
javax.microedition.lcdui. Item yang bisa di tulis public classStringItem
extends Item.
Jadi String Item itu sebuah Item yang dapat diisi String.
Constructor untuk membuat StringItem sendiri ada dua yaitu :
- StringItem(String label, String text)
- StringItem(String label, String text, int appearanceMode)
Untuk appearance mode itu mengatur bentuk tampilan dari String Item
itu sendiri.
Ada 3 fungsi String Item yaitu
- Plain
- Hyperlink
- Button
Untuk lebih jelasnya saya akan meberikan sebuah contoh String Item :
/*
* To change this template, choose Tools |
Templates
* and open the template in the editor.
*/
/**
/**
/**
* @author Arie Akbar Fatria
*/
import
javax.microedition.lcdui.*;
import
javax.microedition.midlet.MIDlet;
public class tugas extends
MIDlet implements CommandListener, ItemCommandListener {
private Display display;
private StringItem string;
Form chform;
Command exitCommand;
Ticker ticker = new Ticker("ARIE AKBAR
FATRIA");
public tugas(){
display
= Display.getDisplay(this);
chform=
new Form("Tugas String Item");
string
= new StringItem("Latihan", "Silahkan Tekan Tombol Ini",
StringItem.BUTTON);
string.setDefaultCommand(List.SELECT_COMMAND);
string.setItemCommandListener(this);
exitCommand
= new Command("Kembali", Command.SCREEN,0);
chform.setTicker(ticker);
chform.addCommand(exitCommand);
chform.append(string);
}
public void startApp() {
display.setCurrent(chform);
}
public void pauseApp() {
}
public void destroyApp(boolean
unconditional) {
}
public void commandAction(Command c, Item
item) {
if(item == string)
{
string.setText("yes");
}
}
public void commandAction(Command c, Displayable
d) {
throw new
UnsupportedOperationException("Not supported yet.");
}
}
0 komentar:
Posting Komentar