- package lab.sodino.filesys;
- import javax.microedition.io.file.FileSystemListener;
- import javax.microedition.io.file.FileSystemRegistry;
- import javax.microedition.lcdui.Alert;
- import javax.microedition.lcdui.AlertType;
- import javax.microedition.lcdui.Display;
- import javax.microedition.lcdui.Form;
- import javax.microedition.midlet.MIDlet;
- import javax.microedition.midlet.MIDletStateChangeException;
- public class FSListenerDemo extends MIDlet implements FileSystemListener {
- public FSListenerDemo() {
- super();
- Form f = new Form("FSDemo");
- Display.getDisplay(this).setCurrent(f);
- }
- protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
- }
- protected void pauseApp() {
- }
- protected void startApp() throws MIDletStateChangeException {
- FileSystemRegistry.addFileSystemListener(this);
- }
- public void rootChanged(int state, String rootName) {
- if (state == FileSystemListener.ROOT_ADDED) {
- Alert alert = new Alert("Information", "A new card has been mounted, it's name is " + rootName, null,
- AlertType.CONFIRMATION);
- alert.setTimeout(Alert.FOREVER);
- Display.getDisplay(this).setCurrent(alert);
- } else if (state == FileSystemListener.ROOT_REMOVED) {
- Alert alert = new Alert("Information", "A new card has been unmounted, it's name is " + rootName, null,
- AlertType.CONFIRMATION);
- alert.setTimeout(Alert.FOREVER);
- Display.getDisplay(this).setCurrent(alert);
- }
- }
- }
posted on 2010-03-19 23:05
鹏凌 阅读(344)
评论(0) 编辑 收藏 所属分类:
java