使用JavaGUI制作简易批处理文件工具

批处理文件工具

引言:不知道小伙伴们平时在生活中处理许多文件的时候有没有遇到过需要处理很多文件名的时候,在Window系统中没有批处理的重命名文件的功能,而MAC OX有这样的小功能,因此制作了简易的批处理文件工具。

MainFrame

package batchfile;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.*;

public class MainFrame extends JFrame {
   
	public static void main(String[] args) {
   
		// TODO Auto-generated method stub
		// 创建窗体
		JFrame frame = new JFrame("BatchFiles");

		// 设置布局为null--清空布局
		frame.setLayout(null);
		// 增加标签
		JLabel dirPath = new JLabel("dirPath:");
		dirPath.setBounds(15, 25, 50, 30);
		frame.add(dirPath);

		JTextField dirPathFileld = new JTextField();
		dirPathFileld.setBounds(70, 25, 390, 30);
		frame.add(dirPathFileld);

		JButton browser = new JButton("Browser");
		browser.setBounds(465, 25, 75, 30);
		frame.add(browser);

		JLabel oldDirName = new JLabel("oldDir:");
		oldDirName.setBounds(15, 60, 75, 30);
		frame.add(oldDirName);

		JTextField oldDirField = new JTextField();
		oldDirField.setBounds(80, 60, 120, 30);
		frame.add(oldDirField);

		JLabel label = new JLabel("=>");
		label.setBounds(205, 60, 50, 30);
		frame.add(label);

		JTextField newDirField = new JTextField();
		newDirField.setBounds(235, 60, 120, 30);
		frame.add(newDirField);

		JLabel newDirName = new JLabel(":newDir");
		newDirName.setBounds(365, 60, 75, 30);
		frame.add(newDirName);
		// 设置撤回按钮

		JButton recallDirButton = new JButton("RecallDir");
		recallDirButton.setBounds(440, 60, 100, 30);
		frame.add(recallDirButton);
		recallDirButton.addActionListener(new ActionListener() {
   

			@Override
			public void actionPerformed(ActionEvent e) {
   
				// TODO Auto-generated method stub
				String filePath = dirPathFileld.getText();
				String oldTonew = oldDirField.getText();
				String recallPathString = FixFileName(filePath, oldTonew);
				dirPathFileld.setText(recallPathString);
			}
		});

		JLabel oldFileName = new JLabel("oldFile:");
		oldFileName.setBounds(15, 100, 75, 30);
		frame.add(oldFileName);

		JTextField oldFileField = new 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值