~ Event Handling = Event sing gunane kanggo nangani interaksi user ambe' program, contoh e user milih
sebuah menu dalam sebuah aplikasi MIDlet. Lha gawe nangani event perlu
"mengimplementasikan" interface CommandListener lan ItemListener.
CommandListener fungsine iku digawe nangani lek pas user milih Command tertentu
lha lek ItemListener fungsine kanggo nangani lek pas user ngganti nilai kook misal e ngubah pilihan nang ChoiceGroup.
Ben sing moco iki ora bingung ambe cara kerjo ne, simak en conto nang nisor iki.
import javax.microedition.MIDlet.*;
import javax.microedition.lcdui.*;
public class NotHelloWorld2 extends MIDlet implements CommandListener{
private Command cmdExit;
private Display display;
public NotHelloWorld2()
{
display = Display.getDisplay(this);
cmdExit = new Command("Exit", Command.SCREEN,2);
}
public void startApp()
{
TextBox t = new TextBox("Not ","Not Hello World",256,0);
t.addCommand(cmdExit);
t.setCommandListener(this);
display.setCurrent(t);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void commandAction(Command cmd,Displayable disp)
{
if(cmd==cmdExit)
{
destroyApp(false);
notifyDestroyed();
}
}
}
import javax.microedition.lcdui.*;
public class NotHelloWorld2 extends MIDlet implements CommandListener{
private Command cmdExit;
private Display display;
public NotHelloWorld2()
{
display = Display.getDisplay(this);
cmdExit = new Command("Exit", Command.SCREEN,2);
}
public void startApp()
{
TextBox t = new TextBox("Not ","Not Hello World",256,0);
t.addCommand(cmdExit);
t.setCommandListener(this);
display.setCurrent(t);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void commandAction(Command cmd,Displayable disp)
{
if(cmd==cmdExit)
{
destroyApp(false);
notifyDestroyed();
}
}
}
Kurang lebih e koyo' ngunu lah, sepurane ora onok sekrinsut e.
Mugo² bermanfaat. :)
Mugo² bermanfaat. :)
Tidak ada komentar:
Posting Komentar