m_filefilter.java

来自「自己用Java写的一个mp3文件改名的小工具」· Java 代码 · 共 83 行

JAVA
83
字号
import java.io.File;

/**
 *  Description of the Class
 *
 * @author     kilo
 * @created    2003年12月22日
 */
public final class m_FileFilter
		 extends javax.swing.filechooser.FileFilter {
	/**
	 *  Description of the Field
	 */
	protected boolean dirInclude;
	/**
	 *  Description of the Field
	 */
	protected String exName;


	/**
	 *  Constructor for the m_FileFilter object
	 *
	 * @param  dirInclude  Description of the Parameter
	 * @param  exName      Description of the Parameter
	 */
	public m_FileFilter( boolean dirInclude, String exName ) {
		this.dirInclude = dirInclude;
		this.exName = exName;
	}


	/**
	 *  Gets the extension attribute of the m_FileFilter class
	 *
	 * @param  f  Description of the Parameter
	 * @return    The extension value
	 */
	private static String getExtension( File f ) {
	String ext = null;
	String s = f.getName();
	int i = s.lastIndexOf( '.' );

		if ( i > 0 && i < s.length() - 1 )
			ext = s.substring( i + 1 ).toLowerCase();

		else
			return "";
		return ext;
	}


	/**
	 *  Description of the Method
	 *
	 * @param  f  Description of the Parameter
	 * @return    Description of the Return Value
	 */
	public boolean accept( File f ) {
		if ( f.isDirectory() && dirInclude == true )
			return true;
		else if ( f.isDirectory() && dirInclude == false )
			return false;
		else {
		String cExtension = getExtension( f );
			if ( cExtension.compareToIgnoreCase( exName ) == 0 )
				return true;
			return false;
		}
	}


	/**
	 *  Gets the description attribute of the m_FileFilter object
	 *
	 * @return    The description value
	 */
	public String getDescription() {
		return "mp3 music Files";
	}

}

⌨️ 快捷键说明

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