在ExampleFileFilter myfilefilter = new ExampleFileFilter();的时候myeclipse提示说ExampleFileFilter不能识别。是为什呢?我找了好多资料: http://joggplayer.webarts.bc.ca/html/docs/api/ca/bc/webarts/widgets/ExampleFileFilter.html 
和 
http://www.vaegar.f9.co.uk/examples/SwingSet_demo/ExampleFileFilter.java.html 但是还是没有解决,也不是要导入什么包还是什么的?我的jdk5.0。 听人说在安装目录下有源代码: 
yourJDK/demo/jfc/FileChooserDemo/ExampleFileFilter.java 但是我的这个目录下却没有这个ExamplefileFilter.java文件。不解 怎么解决,求解!

解决方案 »

  1.   

    http://kickjava.com/src/demo/swingset/ExampleFileFilter.java.htm
      

  2.   

    自己直接写一个类,代码如下:import java.io.File;
    import javax.swing.filechooser.FileFilter;
    import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;
    public class ExampleFileFilter extends FileFilter { 
    private Hashtable filters = null; 
    private String fullDescription = null; 

    public ExampleFileFilter() { 
    this.filters = new Hashtable(); 
    }  public ExampleFileFilter(String extension) { 
    this();  


    public boolean accept(File f) { 
    if(f != null) { 
    if(f.isDirectory()) { 
    return true; 

    String extension = getExtension(f); 
    if(extension != null && filters.get(getExtension(f)) != null) { 
    return true; 
    }; 

    return false; 
    }  public String getExtension(File f) { 
    if(f != null) { 
    String filename = f.getName(); 
    int i = filename.lastIndexOf('.'); 
    if(i>0 && i<filename.length()-1) { 
    return filename.substring(i+1).toLowerCase(); 
    }; 

    return null; 
    }

    public String getDescription() {
    return null;


    public void addExtension(String extension) { 
    if(filters == null) { 
    filters = new Hashtable(5); 

    filters.put(extension.toLowerCase(), this); 
    fullDescription = null; 
    } public void setDescription(String string) {

    }
    }