Tìm kiếm Blog này

Thứ Năm, 28 tháng 10, 2010

danh sach

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

public class ListExample extends MIDlet implements CommandListener
{
private Display display; // Doi tuong Display
private List lsDocument; // Main list
private Command cmExit; // Lenh exit

public ListExample()
{
display = Display.getDisplay(this);

// Tao lenh Exit
cmExit = new Command("Exit", Command.EXIT, 1);

try
{
// Tao mang cac doi tuong anh
Image images[] = {Image.createImage("/Sau.png"),
Image.createImage("/Truoc.png"),
Image.createImage("/Moi.png")};

// Create array of corresponding string objects
String options[] = {"Sau", "Truoc", "Moi"};

// Create list using arrays, add commands, listen for events
lsDocument = new List("Document Option:", List.IMPLICIT, options, images);

// If you have no images, use this line to create the list
// lsDocument = new List("Document Option:", List.IMPLICIT, options, null);

lsDocument.addCommand(cmExit);
lsDocument.setCommandListener(this);
}
catch (java.io.IOException e)
{
System.err.println("Unable to locate or read .png file");
}
}

public void startApp()
{
display.setCurrent(lsDocument);
}

public void pauseApp()
{
}

public void destroyApp(boolean unconditional)
{
}

public void commandAction(Command c, Displayable s)
{
// If an implicit list generated the event
if (c == List.SELECT_COMMAND)
{
switch (lsDocument.getSelectedIndex())
{
case 0:
System.out.println("Option Sau la: selected");
break;

case 1:
System.out.println("Option Truoc la: selected");
break;

case 2:
System.out.println("Option Moi la: selected");
break;

}
}
else if (c == cmExit)
{
destroyApp(false);
notifyDestroyed();
}
}
}

Không có nhận xét nào: