?? filebrowser.java
字號:
/*
* FileBrowser.java
*
* Created on 2007年10月18日
*/
import java.io.IOException;
import java.util.Enumeration;
import javax.microedition.io.*;
import javax.microedition.io.file.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class FileBrowser extends MIDlet implements CommandListener
{
public String currentDir = "";
private Display dspFileBrowse;
private Command exitCommand;
private Command openCommand;
private List fileList;
private String fathorFolder = "..";
public FileBrowser()
{
this.dspFileBrowse = Display.getDisplay(this);
this.fileList = new List("文件瀏覽器", List.IMPLICIT);
this.exitCommand = new Command("退出", Command.EXIT, 1);
this.openCommand = new Command("打開", Command.OK, 1);
this.fileList.addCommand(this.openCommand);
this.fileList.addCommand(this.exitCommand);
this.fileList.setCommandListener(this);
this.dspFileBrowse.setCurrent(this.fileList);
}
public void startApp()
{
this.getRoots();
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
this.notifyDestroyed();
}
public void commandAction(Command command, Displayable displayable)
{
if(command == this.openCommand)
{
this.judgeDir();
}
if(command == this.exitCommand)
{
this.destroyApp(true);
}
}
private void judgeDir()
{
String currSelect = getCurrentSelect();
if(currSelect == "..")
{
int loopTime = this.currentDir.length() - 2;
char[] charTemp = this.currentDir.toCharArray();
char folder ='/';
while(loopTime > 0)
{
if(charTemp[loopTime] == folder)
{
break;
}
loopTime --;
}
if(loopTime == 0)
{
this.getRoots();
}
else
{
this.currentDir = this.currentDir.substring(0, loopTime+1);
this.getFolders(this.currentDir);
}
return;
}
int strLen = currSelect.length();
String lastStr = currSelect.substring(strLen-1, strLen);
if(lastStr.equals("/"))
{
this.currentDir += currSelect;
this.getFolders(this.currentDir);
return;
}
return;
}
private void getRoots()
{
this.currentDir = "";
Enumeration enumRoot = FileSystemRegistry.listRoots();
this.fileList.deleteAll();
while(enumRoot.hasMoreElements())
{
this.fileList.append((String)enumRoot.nextElement(), null);
}
}
private String getCurrentSelect()
{
int a = this.fileList.getSelectedIndex();
String result = this.fileList.getString(a);
return result;
}
private void getFolders(String dir)
{
try
{
FileConnection fc = (FileConnection) Connector.open("file://localhost/" + dir);
Enumeration enumFolders = fc.list();
this.fileList.deleteAll();
this.fileList.append(this.fathorFolder, null);
while(enumFolders.hasMoreElements())
{
String listinfo = (String)enumFolders.nextElement();
this.fileList.append(listinfo, null);
}
} catch (IOException ex)
{
ex.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -