package org.rocking;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.apache.log4j.Logger;
public class MainWindow extends JFrame {
/**
*
*/
private static final long serialVersionUID = -4793216655531089765L;
BorderLayout borderLayout = null;
FlowLayout flowLayout = null;
JFrame frame = new JFrame("");
JPanel mainPanel;
JPanel northPanel;
JPanel centerPanel;
JPanel southPanel;
JButton button = new JButton();
JButton processBtn = new JButton();
JTextField textField = new JTextField(30);
JTextField oldTextField = new JTextField(47);//旧字符串
JTextField newTextField = new JTextField(47);//新字符串
File file = null;
String filePath = "";
static String lastpath = "";//上次路径
Properties properties = new Properties();
public static final Logger logger = Logger.getLogger(MainWindow.class);
public MainWindow() {
//初始化
//--------------------------------------------------------------------------------
//创建布局管理器
//--------------------------------------------------------------------------------
borderLayout = new BorderLayout();
flowLayout = new FlowLayout();
filePath = this.getClass().getResource("/conf.properties").getPath();
lastpath = FileManager.readPropertyValue(filePath, "org.rocking.lastPath");
logger.info("filePath: " + filePath);
logger.info("lastpath: " + lastpath);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser(lastpath); //对话框
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int i = fileChooser.showOpenDialog(getContentPane()); //opendialog
if (i == JFileChooser.APPROVE_OPTION) { //判断是否为打开的按钮
file = fileChooser.getSelectedFile(); //取得选中的文件
textField.setText(file.getPath()); //取得路径
lastpath = file.getPath();
FileManager.writeProperties(filePath, "org.rocking.lastPath", lastpath);
}
}
});
button.setText("选择路径");
button.setSize(50, 20);
processBtn.addActionListener(new ActionListener() {
@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent e) {
boolean tag = true;
if(file != null) {
String oldString = oldTextField.getText();
String newString = newTextField.getText();
if(oldString != null && newString != null) {
try {
new ReplaceAction().execute(file.getAbsolutePath(), oldString, newString);
} catch (IOException e1) {
tag = false;
e1.printStackTrace();
}
} else {
tag = false;
}
} else {
tag = false;
}
JLabel label = new JLabel();
JDialog dialog = new JDialog(frame, "提示信息", true);
dialog.setSize(50, 30);
dialog.setBounds(300, 300, 250, 200);
dialog.getContentPane().add(label);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
if(tag) {
label.setText("处理成功!");
} else {
label.setText("处理失败!");
}
dialog.show();
}
});
processBtn.setText("替换");
processBtn.setSize(50, 20);
JLabel oldTextlabel = new JLabel();
oldTextlabel.setText("旧串");
JLabel newTextlabel = new JLabel();
newTextlabel.setText("新串");
northPanel = new JPanel();
northPanel.setLayout(flowLayout);
northPanel.add(button); //布局处理
northPanel.add(textField);
centerPanel = new JPanel();
centerPanel.setLayout(flowLayout);
centerPanel.add(oldTextlabel);
centerPanel.add(oldTextField);
centerPanel.add(newTextlabel);
centerPanel.add(newTextField);
southPanel = new JPanel();
southPanel.setLayout(flowLayout);
southPanel.add(processBtn);
mainPanel = (JPanel) getContentPane();
mainPanel.setLayout(borderLayout);
mainPanel.add(northPanel, BorderLayout.NORTH);
mainPanel.add(centerPanel, BorderLayout.CENTER);
mainPanel.add(southPanel, BorderLayout.SOUTH);
BufferedImage image = null;
try {
image = ImageIO.read(this.getClass().getResource("icon.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
frame.setIconImage(image);
frame.getContentPane().add(mainPanel);
frame.setTitle("字符串批量替换");
/* Image icon = Toolkit.getDefaultToolkit().getImage("");
frame.setIconImage(icon);//去掉图标
*/ frame.setSize(600, 270);
frame.setVisible(true);
frame.setBounds(300, 300, 600, 270);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new MainWindow();
}
}
鹏_鹏
- 粉丝: 50
- 资源: 15
最新资源
- 数据分析-02-淘宝用户行为分析(包含代码和数据)
- (1160222)线性代数试卷
- 毕业设计基于Python+机器学习的股票预测和分析项目源码+文档说明.zip
- 机械设计TB66004A电机驱动器模型step非常好的设计图纸100%好用.zip
- (26144420)线性代数试题库11套题.doc
- BERNESE所需的DE405.EPH文件
- 数据分析-03-上海餐饮情况分析(包含代码和数据)
- modbust调试助手
- (179942656)JavaWeb实验二 JSP表单开发及访问数据库【源代码+注释】
- 基于pytorch的股票预测和分析项目源码+文档说明.zip
- (1729410)jsp数据库编程指南
- (14659434)数码管动态显示
- (25363252)新颖的单片机实现测温电路
- 数据分析-04-百货商场用户画像描述与价值分析(包含代码和数据)
- Python毕业设计-基于pytorch的股票预测和分析项目源码+文档说明.zip
- (2627236)学生成绩管理信息系统
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈