⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filemanage.java

📁 手机文本浏览器
💻 JAVA
字号:
package com.cnxinshe.noteview;

import java.util.Enumeration;

import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.FileSystemRegistry;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;

public class FileManage implements CommandListener,Runnable{
	private boolean  statequan=false;
private String filePath="";
private FileConnection fc=null;
private Display dis=null;
private Alert alert=new Alert("提示","真的要退出吗?",null,AlertType.WARNING);
private List list=new List("",List.IMPLICIT);
private String curr="";
private String path="";
private String lt="";
private int index=0;
private int set=0;
private boolean state=false;
private boolean first=true;
private boolean state01=false;

private Command view=new Command("退出",Command.SCREEN,1);
private Command view01=new Command("查看",Command.SCREEN,1);
private Command exit=new Command("查看",Command.BACK,1);
private Command exitOk=new Command("确定",Command.OK,1);
private Command exitCancel=new Command("取消",Command.CANCEL,1);
private Command back=new Command("返回",Command.BACK,1);

private Image dir=null;
private Image file=null;
private Main instance;
public FileManage(Display dis,Main instance){
	this.dis=dis;
	this.instance=instance;
   try{
    dir=Image.createImage("/dir.png");
    file=Image.createImage("/file.png");
   }catch(Exception ex){
    ex.printStackTrace();
   }
   alert.addCommand(exitOk);
   alert.addCommand(exitCancel);
   alert.setCommandListener(this);
   this.startApp();
}

public void startApp(){

   list.setFitPolicy(List.TEXT_WRAP_OFF);
   
   viewFileSystem();  
}

public void pauseApp(){
  
}


public void commandAction(Command c,Displayable d){
//   if(c==exit){
//    dis.setCurrent(alert);
//   
//   }else if(false){
//	   filePath=  fc.getPath();
//	  
//	  
//	 if( filePath.substring(filePath.length()-4).equals(".txt")){
//	 
//		 NoteView noteView=new NoteView(dis,filePath);
//	 }
//	 
//   }
//   else 
	
	if(c==view){
		
	   Midlet_Main midlet_Main	=new Midlet_Main( dis,"/ro.txt",instance);
	   
		midlet_Main.startApp();
		
    
   }if(c==back)
	
	     state=true;    
 Thread td=new Thread(this);
 td.start();
  
//   else if(c==exitOk){
//	   instance.notifyDestroyed();
// 
//   }
//   else if(c==exitCancel){
//	 
//    dis.setCurrent(list);
//   }
  
}

public void run(){
   prepare();
}

public void prepare(){
   String curr;
   index=list.getSelectedIndex();  
   curr=list.getString(index);
   if(!curr.endsWith("/")&&!curr.equals(".."))
    return ;
   else if(curr.equals("..")||state){
    int i=path.lastIndexOf('/');  
    path=path.substring(0,i);
    i=path.lastIndexOf('/');
    path=path.substring(0,i+1);
    i=lt.lastIndexOf(';');
    String s=lt.substring(i+1,lt.length());
    lt=lt.substring(0,i);
    set=Integer.parseInt(s);
    state=false;
   }
   else{
    lt+=";"+index;
    path+=curr;
    set=0;
   }
  
   viewFileSystem();
}

public void viewFileSystem(){
   list.deleteAll();
   Enumeration e=null;
   try{
    if(path.length()==0){
     e=FileSystemRegistry.listRoots();
     list.removeCommand(back);
     list.addCommand(exit);
    }
    else {
     fc=(FileConnection)Connector.open("file://localhost/"+path);
     e=fc.list();
 

     list.append("..",dir);
     list.removeCommand(exit);
     list.addCommand(back); 
    } 
   }catch(Exception ex){
    ex.printStackTrace();
   }  
   while(e.hasMoreElements()){
    curr=(String)e.nextElement();
    if(curr.endsWith("/")|path.length()==0)
     list.append(curr,dir);
    else
     list.append(curr,file);
   }
   if(first){
    list.addCommand(exit);
    list.addCommand(view);  
    list.setSelectCommand(view);
    list.setCommandListener(this);
    first=false;
   }
   list.setSelectedIndex(set,true);
   list.setTitle(path);
   dis.setCurrent(list);
}

public List getList() {
	return list;
}

public void setList(List list) {
	this.list = list;
}

public String getFilePath() {
	return filePath;
}

public boolean isStatequan() {
	return statequan;
}

public void setStatequan(boolean statequan) {
	this.statequan = statequan;
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -