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);
                    
//                
            }
        });

java自定义对话框的更多相关文章

  1. Android中的AlertDialog使用示例五(自定义对话框)

    在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式. ...

  2. android继承Dialog实现自定义对话框

    有时需要自定义对话框,可以使用AlterDialog.Bulider,比如下面的代码片段 new AlertDialog.Builder(self) .setTitle("标题") ...

  3. 关于JFace的自定义对话框(Dialog类)

    仅仅是使用MessageDialog,InputDialog等JFace中现成的对话框类是无法满足实际项目开发需要的. 很多时候都需要自己定制对话框,自定义对话框只要在Dialog类的基础上作扩展就行 ...

  4. android创建自定义对话框

    创建如下自定义对话框: JAVA代码 LayoutInflater li = LayoutInflater.from(TagActivity. this);  //NOTE final View Te ...

  5. Android 常见对话框的简单使用(提示信息对话框、单选多选对话框、自定义对话框)

    目录 一.提示信息对话框: 二.单选对话框: 三.多选对话框: 四.自定义对话框: 演示项目完整代码: 一.提示信息对话框: //显示提示消息对话框 private void showMsgDialo ...

  6. Android—关于自定义对话框的工具类

    开发中有很多地方会用到自定义对话框,为了避免不必要的城府代码,在此总结出一个工具类. 弹出对话框的地方很多,但是都大同小异,不同无非就是提示内容或者图片不同,下面这个类是将提示内容和图片放到了自定义函 ...

  7. java自定义注解类

    一.前言 今天阅读帆哥代码的时候,看到了之前没有见过的新东西, 比如java自定义注解类,如何获取注解,如何反射内部类,this$0是什么意思? 于是乎,学习并整理了一下. 二.代码示例 import ...

  8. jquery自定义对话框alert、confirm和prompt

    jQuery Alert Dialogs,又一个基于jQuery的提示框插件,主要包括Alert.Confirm.prompt这三种,还有一个高级范例,可以在提示框内嵌入HTML语言,可以自定义风格样 ...

  9. Android自定义对话框

    在android中有自带的对话框,为了美观,很多开发者会使用自定义对话框,如下图: 点击“弹出自定义对话框按钮后”显示如图效果. 首先要自己定义一个xml文件定义自己对话框的样式: <?xml ...

随机推荐

  1. 『重构--改善既有代码的设计』读书笔记----Move Field

    在类与类之间搬移状态和行为,是重构过程中必不可少的步骤.很有可能在你现在觉得正常的类,等你到了下个礼拜你就会觉得不合适.或者你在下个礼拜创建了一个新的类并且你需要讲现在类的部分字段和行为移动到这个新类 ...

  2. 原生js实现回到顶部

    网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.offset ...

  3. 原型链和new

    http://www.cnblogs.com/objectorl/archive/2010/01/11/Object-instancof-Function-clarification.html 构造器 ...

  4. Ajax之HTTp请求

    71.Ajax的基础概念  *运用html和css来实现页面表达信息  *运用XMLHttpRequest和web服务器进行数据的异步交换  *运用JavaScript操作DOM来实现动态局部刷新 2 ...

  5. Devexpress Barmanager设置

    一,在bar的属性中有optionbar,可以做一些设置. 其中比较有用的是:1,去掉最右边的箭头:allowquickcustomization 改为false 2,去掉最左边的竖线:drawdra ...

  6. js获取返回首页

    <script>setTimeout(function(){    window.location.href="http://"+window.location.hos ...

  7. int*-------int

    a=(int)((int*)0 + 4)求a是多少 大家看图应该明白了  十六进制0x00000010转换为十进制就是16

  8. bzoj2395: [Balkan 2011]Timeismoney

    Description      有n个城市(编号从0..n-1),m条公路(双向的),从中选择n-1条边,使得任意的两个城市能够连通,一条边需要的c的费用和t的时间,定义一个方案的权值v=n-1条边 ...

  9. BZOJ 3744 Gty的妹子序列

    Description 我早已习惯你不在身边, 人间四月天 寂寞断了弦. 回望身后蓝天, 跟再见说再见-- 某天,蒟蒻Autumn发现了从 Gty的妹子树上掉落下来了许多妹子,他发现 她们排成了一个序 ...

  10. 【HDOJ】2369 Broken Keyboard

    字符串. #include <cstdio> #include <cstring> ]; ]; int main() { int n, len; int i, j, k, tm ...