FilerForm.java
上传用户:kyckim
上传日期:2007-12-11
资源大小:332k
文件大小:2k
- package Tonttu;
- import java.util.Enumeration;
- import javax.microedition.io.Connector;
- import javax.microedition.io.file.FileConnection;
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.CommandListener;
- import javax.microedition.lcdui.Display;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.lcdui.Form;
- import javax.microedition.lcdui.Item;
- import javax.microedition.lcdui.ItemCommandListener;
- import javax.microedition.lcdui.StringItem;
- public class FilerForm extends Form implements CommandListener, ItemCommandListener {
-
- final String PATH = TonttuMIDlet.tonttuMIDlet.getAppProperty("Directry");
-
- private Command[] command = new Command[1];
- private Enumeration files = null;
- private FileConnection fc = null;
-
- FilerForm() {
- super("Select a file");
-
- command[0] = new Command("Cancel", Command.EXIT, 1);
- addCommand(command[0]);
- setCommandListener(this);
-
- openDir();
- }
-
- private void openDir() {
- try {
- fc=(FileConnection) Connector.open(PATH ,Connector.READ);
- files = fc.list();
- } catch(Exception e) {
- return;
- }
- deleteAll();
- String str;
- while(files.hasMoreElements()) {
- str = (String)files.nextElement();
- if(str.toLowerCase().endsWith(".mp3") || str.toLowerCase().endsWith(".aac") || str.toLowerCase().endsWith(".m4a")) {
- addItem(str);
- }
- }
- }
-
- private void addItem(String fileName) {
- StringItem item = new StringItem("", fileName);
- item.setLayout(Item.LAYOUT_2|Item.LAYOUT_NEWLINE_AFTER);
- item.setDefaultCommand(new Command("Open", Command.SCREEN,0));
- item.setItemCommandListener(this);
- append(item);
- }
-
- public void commandAction(Command c, Item item) {
- // String filePath = PATH + "/" + ((StringItem)item).getText();
- if(TonttuMIDlet.tonttuMIDlet.playerCanvas.player != null) {
- TonttuMIDlet.tonttuMIDlet.playerCanvas.closePlayer();
- }
- // TonttuMIDlet.tonttuMIDlet.playerCanvas.getPlayer(filePath);
- TonttuMIDlet.tonttuMIDlet.playerCanvas.getPlayer(((StringItem)item).getText());
- Display.getDisplay(TonttuMIDlet.tonttuMIDlet).setCurrent(TonttuMIDlet.tonttuMIDlet.playerCanvas);
- }
-
- public void commandAction(Command c, Displayable d) {
- if(c == command[0]) {
- Display.getDisplay(TonttuMIDlet.tonttuMIDlet).setCurrent(TonttuMIDlet.tonttuMIDlet.playerCanvas);
- }
- }
- }