哪位桶子,哦sorry,是同志给个FileDialog的FilenameFilter用法的示例(完整一些),兄弟我涕淋不尽..
来源: 互联网 发布时间:2014-12-28
本文导语: 无 | //这是一个简单的filedialog的filenamefilter例子 //希望对你有用.别忘了给分呀. import java.io.*; import java.util.*; import java.awt.*; import javax.swing.*; class MyFilenameFilter implements FilenameFilter { ...
无
|
//这是一个简单的filedialog的filenamefilter例子
//希望对你有用.别忘了给分呀.
import java.io.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;
class MyFilenameFilter implements FilenameFilter {
public boolean accept(File f,String name) {
StringTokenizer st = new StringTokenizer(name,".");
String token = "";
while (st.hasMoreTokens())
token = st.nextToken();
if (token.equals("gif")) return true;
else return false;
}
}
public class Test extends JFrame {
public static void main(String[] args) {
Frame parent = new Frame();
MyFilenameFilter filter = new MyFilenameFilter();
FileDialog dialog = new FileDialog(parent, "Choose File");
dialog .setFile("*.gif");
dialog.setFilenameFilter(filter);
dialog.setVisible(true);
String selectedFile = dialog.getFile();
}
}
//希望对你有用.别忘了给分呀.
import java.io.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;
class MyFilenameFilter implements FilenameFilter {
public boolean accept(File f,String name) {
StringTokenizer st = new StringTokenizer(name,".");
String token = "";
while (st.hasMoreTokens())
token = st.nextToken();
if (token.equals("gif")) return true;
else return false;
}
}
public class Test extends JFrame {
public static void main(String[] args) {
Frame parent = new Frame();
MyFilenameFilter filter = new MyFilenameFilter();
FileDialog dialog = new FileDialog(parent, "Choose File");
dialog .setFile("*.gif");
dialog.setFilenameFilter(filter);
dialog.setVisible(true);
String selectedFile = dialog.getFile();
}
}
|
//对不起,刚才的程序有一点不完善
//用这个试试
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JFrame {
public static void main(String[] args) {
Frame parent = new Frame();
MyFilenameFilter filter = new MyFilenameFilter();
FileDialog dialog = new FileDialog(parent, "Choose File");
dialog .setFile("*.gif");
dialog.setFilenameFilter(filter);
dialog.setVisible(true);
String selectedFile = dialog.getFile();
System.out.println(selectedFile);
if(selectedFile!=null)
System.exit(0);
}
}
class MyFilenameFilter implements FilenameFilter {
public boolean accept(File f,String name) {
StringTokenizer st = new StringTokenizer(name,".");
String token = "";
while (st.hasMoreTokens())
token = st.nextToken();
if (token.equals("gif")) return true;
else return false;
}
}
//用这个试试
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JFrame {
public static void main(String[] args) {
Frame parent = new Frame();
MyFilenameFilter filter = new MyFilenameFilter();
FileDialog dialog = new FileDialog(parent, "Choose File");
dialog .setFile("*.gif");
dialog.setFilenameFilter(filter);
dialog.setVisible(true);
String selectedFile = dialog.getFile();
System.out.println(selectedFile);
if(selectedFile!=null)
System.exit(0);
}
}
class MyFilenameFilter implements FilenameFilter {
public boolean accept(File f,String name) {
StringTokenizer st = new StringTokenizer(name,".");
String token = "";
while (st.hasMoreTokens())
token = st.nextToken();
if (token.equals("gif")) return true;
else return false;
}
}
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。