简体   繁体   English

是否将批处理脚本集成到Java GUI中?

[英]Integrating batch script into Java GUI?

This question is also asked by me: How to integrate batch script multiple selections into JAVA GUI? 我也问了这个问题: 如何将批处理脚本的多个选择集成到JAVA GUI中?

As I did not get a suitable answer for my question, that's why I decided to ask again in stackoverflow with a more short and sweet manner. 由于我的问题没有得到合适的答案,所以这就是为什么我决定以更简短,更甜蜜的方式在stackoverflow中再次询问。 Disclaimer: I edited the question in that site. 免责声明:我在该网站上编辑了问题。 That's why I couldn't find a suitable answer for my question. 这就是为什么我找不到适合我问题的答案的原因。

I have this batch script which needs to be integrated into a java coding. 我有此批处理脚本,需要将其集成到Java编码中。 But this is the first time I am doing integration so I am not familiar how it should be done. 但这是我第一次进行集成,因此我不熟悉应如何进行。

It would be good if anyone can answer my question in that site. 如果有人可以在该站点回答我的问题,那将是很好的。 But if you aren't, it would also be good to provide me with an example of integrating multiple selection batch script into java. 但是,如果不是这样,向我提供将多选批处理脚本集成到Java中的示例也将是一件好事。

eading through your original post, i can conclude that your solution will be quite easy : 通过您的原始帖子,我可以得出结论,您的解决方案将非常简单:

private static String cmdLine = "";
private static final String scriptFile = "MYSCRIPT.sh"

   public GUI() {
        setTitle("FAMILY");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);



    JCheckBox chckbxMyFatherIs = new JCheckBox("My Father is Joe");
    chckbxMyFatherIs.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
           if(!cmdLine.contains("JOE"))
             cmdLine += " JOE ";
        }
    });
    chckbxMyFatherIs.setBounds(45, 48, 137, 23);
    contentPane.add(chckbxMyFatherIs);

    JCheckBox chckbxNewCheckBox = new JCheckBox("My Mother is Audrey");
    chckbxNewCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
           if(!cmdLine.contains("AUDREY"))
             cmdLine += " AUDREY ";
        }
    });
    chckbxNewCheckBox.setBounds(196, 48, 198, 23);
    contentPane.add(chckbxNewCheckBox);

    JCheckBox chckbxNewCheckBox_1 = new JCheckBox("My Bother is Jerry");
    chckbxNewCheckBox_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
           if(!cmdLine.contains("JERRY"))
             cmdLine += " JERRY ";
        }
    });
    chckbxNewCheckBox_1.setBounds(45, 97, 137, 23);
    contentPane.add(chckbxNewCheckBox_1);

    JCheckBox chckbxNewCheckBox_2 = new JCheckBox("My eldest Sister is June ");
    chckbxNewCheckBox_2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
           if(!cmdLine.contains("JUNE"))
             cmdLine += " JUNE ";
        }
    });
    chckbxNewCheckBox_2.setBounds(196, 97, 198, 23);
    contentPane.add(chckbxNewCheckBox_2);

    JCheckBox chckbxNewCheckBox_3 = new JCheckBox("My youngest sister is Awy");
    chckbxNewCheckBox_3.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
           if(!cmdLine.contains("AWY"))
             cmdLine += " AWY ";
       }
    });
    chckbxNewCheckBox_3.setBounds(196, 149, 198, 23);
    contentPane.add(chckbxNewCheckBox_3);

    JCheckBox chckbxAll = new JCheckBox("All");
    chckbxAll.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {               
             cmdLine = "JOE AUDREY JERRY JUNE AWY";
        }
    });
    chckbxAll.setBounds(45, 149, 97, 23);
    contentPane.add(chckbxAll);
}

You will also need an event-listener for your OK-button, in which you can call: 您还需要为“确定”按钮设置一个事件监听器,您可以在其中调用:

Runtime.getRuntime().exec(scriptFile + cmdLine);

Mind you : this will only ADD parameters to your list, removal (via un-ticking the boxes) also needs to be handled ... i think you now know how. 提醒您:这只会将参数添加到您的列表中,也需要处理(通过取消选中框)删除...我想您现在知道如何。 Consider using a list instead of one single string ... thats less messy and allows for dynamic lookup/removal/addition of parameters. 考虑使用列表而不是一个字符串...这样可以减少混乱,并允许动态查找/删除/添加参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM