📄 fileform.java
字号:
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
public class FileForm extends Form implements CommandListener,ItemCommandListener
{
//固定命令
private Command exit, add;
//Item命令
private Command del, delAll;
//
private MainSelect mainSelect;
private String[] musicPath, musicName;
public FileForm(MainSelect ms)
{
super("背景音乐设置");
mainSelect = ms;
exit=new Command("退出",Command.EXIT,1);
add=new Command("添加",Command.OK,1);
del=new Command("删除",Command.OK,1);
delAll=new Command("删除全部",Command.OK,1);
setCommandListener(this);
addCommand(exit);
addCommand(add);
getMusicList();
}
public void commandAction(Command com, Displayable dis)
{
if(com == exit)
Chess.dis.setCurrent(mainSelect);
if(com == add)
{
FileListForm form = null;
try
{
form = new FileListForm(0, this);
}
catch(SecurityException se)
{
Alert alert=new Alert("Message","当前的安全设置不允许使用文件系统操作",null,AlertType.WARNING);
Chess.dis.setCurrent(alert, this);
return;
}
Chess.dis.setCurrent(form);
}
}
public void commandAction(Command com, Item item)
{
if(com == del)
{
String text = ((StringItem)item).getText();
for(int i = 0; i < musicName.length; i++)
{
if(musicName[i].equals(text))
delMusic(i);
}
}
if(com == delAll)
delAllMusic();
}
private void getMusicList()
{
//System.out.println("进入getMusicList()方法");
MusicRecord musicRecord = null;
try
{
musicRecord = new MusicRecord();
}
catch(RecordStoreException e)
{
Alert alert=new Alert("Message","打开音乐记录时出现异常,请稍后重试",null,AlertType.WARNING);
Chess.dis.setCurrent(alert, this);
return;
}
//System.out.println("打开记录成功");
try
{
//System.out.println("开始获取musicList");
musicPath = musicRecord.getMusicList();
//System.out.println("获取musicList完毕:"+musicPath);
}
catch(RecordStoreException rse)
{
Alert alert=new Alert("Message","获取音乐列表时出现异常,请稍后重试",null,AlertType.WARNING);
Chess.dis.setCurrent(alert, this);
return;
}
if(musicPath == null)
musicPath = new String[0];
//System.out.println("musicPath的长度是:"+musicPath.length);
musicName = new String[musicPath.length];
//处理数据的临时变量
StringItem musicItem = null;
int id = 0;
for(int i = 0; i < musicPath.length; i++)
{
id = musicPath[i].lastIndexOf('/');
musicName[i] = musicPath[i].substring(id + 1);
musicItem = new StringItem(null, musicName[i], Item.PLAIN);
musicItem.addCommand(del);
musicItem.addCommand(delAll);
musicItem.setItemCommandListener(this);
append(musicItem);
//append("\n");
}
musicRecord.closeMusicRecord();
}
public void addMusic(String path)
{
MusicRecord musicRecord = null;
try
{
musicRecord = new MusicRecord();
}
catch(RecordStoreException e)
{
Alert alert=new Alert("Message","打开音乐记录时出现异常,请稍后重试",null,AlertType.WARNING);
Chess.dis.setCurrent(alert, this);
return;
}
musicRecord.addMusic(path);
musicRecord.closeMusicRecord();
deleteAll();
getMusicList();
}
private void delMusic(int i)
{
MusicRecord musicRecord = null;
try
{
musicRecord = new MusicRecord();
}
catch(RecordStoreException e)
{
Alert alert=new Alert("Message","打开音乐记录时出现异常,请稍后重试",null,AlertType.WARNING);
Chess.dis.setCurrent(alert, this);
return;
}
musicRecord.delMusic(i);
musicRecord.closeMusicRecord();
deleteAll();
getMusicList();
}
private void delAllMusic()
{
try
{
RecordStore.deleteRecordStore("MusicRecord");
}
catch(RecordStoreException e)
{
Alert alert=new Alert("Message","删除全部音乐记录时出现异常",null,AlertType.WARNING);
Chess.dis.setCurrent(alert, this);
return;
}
deleteAll();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -