资源简介
java实现根据文件名查找本地文件,该程序可直接放在eclipse或者Myeclipse中则可运行,不需要下载其他什么工具包,为开发人员节省了很多时间
代码片段和文件信息
package test;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.Jframe;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class UIfileSearch extends Jframe {
public UIfileSearch() {
this.settitle(“文件搜索JAVA实现“);
this.setSize(600400);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
this.add(new SearchFilePanel());
}
public static void main(String[] args) {
UIfileSearch test = new UIfileSearch();
System.out.println(“5“);
test.setVisible(true);
}
}
class SearchFilePanel extends JPanel{
/**
* 路径浏览和查找按钮
* Buttons for browsing the file system and for starting the search
*/
private JButton browsesearch;
/**
* 查找条件,路径,查找过程
* the conditionsdirectoryprocess of Searching
*/
private JLabel filter directorystatusShow1statusShow2;
/**
* 输入查找条件和路径的文本框
* TextField for inputing the search filter and the file path
*/
private JTextField textFiltertextDirectory;
/**
* 显示查找结果的文本区
* the textArea to show the result of searching
*/
private JTextArea result;
private File selectedFile;
/**
* 找到的文件数量
* number of file had found
*/
private long countFiles;
/**
* temporary variable to store the and
*/
private String p f;
public SearchFilePanel() {
filter = new JLabel(“全部或者部分文件名:“2);
directory = new JLabel(“查找:“2);
statusShow1 = new JLabel(“准备收索...“2);
statusShow2 = new JLabel(“被发现的文件数:“);
textFilter = new JTextField(15);
textDirectory = new JTextField(15);
result = new JTextArea();
result.setEditable(false);
JScrollPane js = new JScrollPane(result);
browse = new JButton(“浏览“);
search = new JButton(“开始收索“);
/**
* 给浏览按钮设置监听事件
* add ActionListener for button browse directly
*/
browse.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
JFileChooser jfc = new JFileChooser();
//Just choose a directory address
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int d = jfc.showDialog(null “Browse the files“);
if(d == JFileChooser.APPROVE_OPTION) {
selectedFile = jfc.getSelectedFile();
textDirectory.setText(selectedFile.getPath());
}
相关资源
- java 毕业设计 进销存管理系统 源码
- java图片浏览器跨平台运行程序与源码
- 基于java的在线考试系统-毕业设计
- 微博系统(Java源码,servlet+jsp),适
- java串口通信全套完整代码-导入eclip
- jsonarray所必需的6个jar包.rar
- 三角网构TIN生成算法,Java语言实现
- java代码编写将excel数据导入到mysql数据
- Java写的cmm词法分析器源代码及javacc学
- JAVA JSP公司财务管理系统 源代码 论文
- JSP+MYSQL旅行社管理信息系统
- 推荐算法的JAVA实现
- 基于Java的酒店管理系统源码(毕业设
- java-图片识别 图片比较
- android毕业设计
- java23种设计模式+23个实例demo
- java Socket发送/接受报文
- JAVA828436
- java界面美化 提供多套皮肤直接使用
- 在线聊天系统(java代码)
- 基于Java的图书管理系统807185
- java中实现将页面数据导入Excel中
- java 企业销售管理系统
- java做的聊天系统(包括正规课程设计
- Java编写的qq聊天室
- 商店商品管理系统 JAVA写的 有界面
- JAVA开发聊天室程序
- 在linux系统下用java执行系统命令实例
- java期末考试试题两套(答案) 选择(
- JAVA3D编程示例(建模、交互)
评论
共有 条评论