gpt4 book ai didi

audio - 如何显示J2me中其他类的列表(LCDUI)?

转载 作者:行者123 更新时间:2023-12-03 02:25:42 26 4
gpt4 key购买 nike

我有一个用于从手机存储器浏览文件的类,它使用list附加文件列表,而我还有另一个类作为mainInterface。

所以我怎样才能将该列表类调用到mainInterface中呢?

这是文件浏览器类

public class FileBrowser implements CommandListener {

private String currDirName;
protected String fileName;
private Command open = new Command("Open", Command.ITEM, 1);
private Command back = new Command("Back", Command.BACK, 2);
private Command exit = new Command("Exit", Command.EXIT, 3);

private final static String UP_DIR = "...";
private final static String MEGA_ROOT = "/";
private final static String SEP_STR = "/";
private final static char SEP = '/';

public Display d;

public FileBrowser(){

currDirName = MEGA_ROOT;
fileName = null;
}

public String getFileName(){
return fileName;
}

public void startBrowsing(){
boolean isAPIAvailable = false;

if(System.getProperty("microedition.io.FileConnection.version") != null){
isAPIAvailable = true;
try{
showCurrDir();



}catch(SecurityException se){}
catch(Exception e){}
}
else{ }
}
public void showCurrDir(){
Enumeration e;
FileConnection currDir = null;
List browser;
try{
if(MEGA_ROOT.equals(currDirName)){
e = FileSystemRegistry.listRoots();
browser = new List(currDirName, List.IMPLICIT);

}
else{
currDir = (FileConnection)Connector.open("file://localhost/" + currDirName);
e = currDir.list();
browser = new List(currDirName, List.IMPLICIT);
browser.append(UP_DIR, null);
}
while(e.hasMoreElements()){
fileName = (String)e.nextElement();
if(fileName.charAt(fileName.length()-1) == SEP){
browser.append(fileName, null);

} else{
browser.append(fileName, null);
}
}
browser.setSelectCommand(open);
browser.addCommand(exit);
browser.setCommandListener(this);
if(currDir != null){
currDir.close();

}

} catch(IOException ioe){}

}
public void commandAction(Command c, Displayable d){
if(c == open){
List curr = (List)d;
final String currFile = curr.getString(curr.getSelectedIndex());
new Thread(new Runnable()
{
public void run()
{
if (currFile.endsWith(SEP_STR) ||
currFile.equals(UP_DIR)) {
traverseDirectory(currFile);
}
else {
openFile(currFile);
}
}
}).start();
}
else if (c == back)
{
showCurrDir();
}

}
public void traverseDirectory(String fileName){
if(currDirName.equals(MEGA_ROOT)){
if(fileName.equals(UP_DIR)){
return;
}
currDirName = fileName;
} else if(fileName.equals(UP_DIR)){
int i = currDirName.lastIndexOf(SEP, currDirName.length()-2);
if(i != -1){
currDirName = currDirName.substring(0, i+1);
}
else{
currDirName = MEGA_ROOT;
}
}
showCurrDir();
}
public void openFile(String fileName){
try{
FileConnection fc = (FileConnection) Connector.open("file://localhost/" + currDirName + fileName);
if(!fc.exists()){
throw new IOException("File does not exists");
}
InputStream fileIS = fc.openDataInputStream();
byte[] b = new byte[1024];

int length = fileIS.read(b, 0, 1024);
fileIS.close();
fc.close();
TextBox tb = new TextBox("View File: " + fileName, null, 1024, TextField.ANY | TextField.UNEDITABLE);
tb.addCommand(back);
tb.addCommand(exit);
tb.setCommandListener(this);

if (length > 0)
{
tb.setString(new String(b, 0, length));
}
} catch(Exception e){}

}

}

这是mainInterface类的代码片段中的函数
public void actionPerformed(ActionEvent ae){
if(ae.getSource() == open){
start the filebrowsing screen
}
}

最佳答案

您需要将其移植到LWUIT才能正常工作。 LWUITDemo的1.4版本在树部分中包含文件树演示。这也是LWUIT聊天演示的一部分。

关于audio - 如何显示J2me中其他类的列表(LCDUI)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5367659/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com