package com.matp.view;
import java.awt.FlowLayout;
public class SimpleDialog extends JDialog implements ActionListener {
// 文本框,用于输入字符串
JTextField field;
JTextField field2;
// 对话框的父窗体。
RecordTestCaseWin parent;
// “确定”按钮
JButton setButton;
/**
* 构造函数,参数为父窗体和对话框的标题
*/
public SimpleDialog(JFrame prentFrame, String title) {
// 调用父类的构造函数,
// 第三个参数用false表示允许激活其他窗体。为true表示不能够激活其他窗体
super(prentFrame, title, false);
// parent = (RecordTestCaseWin) prentFrame;
// 添加Label和输入文本框
JPanel p1 = new JPanel();
JLabel label = new JLabel("请输入项目名称:");
p1.add(label);
field = new JTextField(30);
field.addActionListener(this);
p1.add(field);
getContentPane().add("North", p1);
// 添加Label和输入文本框
JPanel p3 = new JPanel();
JLabel label2 = new JLabel("请输入脚本名称:");
p3.add(label2);
field2 = new JTextField(30);
field2.addActionListener(this);
p3.add(field2);
getContentPane().add("Center", p3);
// 添加确定和取消按钮
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout(FlowLayout.RIGHT));
JButton cancelButton = new JButton("取 消");
cancelButton.addActionListener(this);
setButton = new JButton("确 定");
setButton.addActionListener(this);
p2.add(setButton);
p2.add(cancelButton);
getContentPane().add("South", p2);
// 调整对话框布局大小
pack();
}
/**
* 事件处理
*/
public void actionPerformed(ActionEvent event) {
Object source = event.getSource();
if ((source == setButton)) {
// 如果确定按钮被按下,则将文本矿的文本添加到父窗体的文本域中
// parent.setText(field.getText());
// File f = new File(".\\config\\save\\shutter_button.txt");
// File fw = new File("D:\\MATP_robot");
String Txtname = field.getText();
File file3 =new File("D:\\MATP_robot"+"\\"+ Txtname);
//如果文件夹不存在则创建
if (!file3 .exists() && !file3 .isDirectory())
{
System.out.println("//不存在");
file3 .mkdir();
} else
{
System.out.println("//目录存在");
}
File file = new File(".\\config\\batfolder\\Matp.bat");
if (file.exists()) {
file.delete();
}
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(
".\\config\\batfolder\\Save.bat", true));
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
writer.write("echo off" + "\r\n");
writer.write("copy .\\config\\shutter_button.txt "+ "D:\\MATP_robot"+"\\"+Txtname
+ "\r\n");
writer.flush();
writer.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
RAMThreadOn mRAMThreadOn = new RAMThreadOn();
mRAMThreadOn.run();
String Txtname2 = field2.getText();
File f = new File("D:\\MATP_robot\\"+"\\"+Txtname+"\\"+"shutter_button.txt");
System.out.println(f);
f.renameTo(new File("D:\\MATP_robot\\" + "\\"+Txtname+"\\" + Txtname2 + ".txt"));
System.out.println(f + "========11========");
JOptionPane.showMessageDialog(null, "脚本保存在D:\\MATP_robot"+"\\"+Txtname+"目录中");
field2.setText("");
}
field.selectAll();
// 隐藏对话框
setVisible(false);
}
}
调用类
exportBtn.addActionListener(new ActionListener() {
// @Override
public void actionPerformed(ActionEvent arg0) {
// RAMThreadOn mRAMThreadOn = new RAMThreadOn();
// mRAMThreadOn.run();
// String Txtname = fileName.getText();
// File f = new File(".\\config\\save\\shutter_button.txt");
// // File f = new File(".\\config\\save\\shutter_button.txt");
// System.out.println(f);
// f.renameTo(new File(".\\config\\save\\" + Txtname + ".txt"));
// System.out.println(f + "========11========");
// JOptionPane.showMessageDialog(null, "脚本保存在config\\save目录中");
// fileName.setText("");
if (dialog == null) {
dialog = new SimpleDialog(prentFrame, " vcv ");
}
dialog.setVisible(true);
dialog.setLocation(500, 400);
//
}
});