0

This question is also asked by me: How to integrate batch script multiple selections into 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. 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. 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.

Community
  • 1
  • 1
Steven
  • 107
  • 2
  • 14
  • about programming skills, nor (not) about "get me perfect solution for me" – mKorbel Jul 27 '14 at 16:27
  • why arent you using java console-input/output? Thats MUCH less error-prone than fiddling with batch, you obviously want to create a PROGRAM and not a little SCRIPT. Mixing these two things always yields big problems ... a common beginners' mistake – specializt Jul 27 '14 at 16:34
  • @mKorbel i am not looking for perfect solution. I just started learning batch scripting and java 1-2 months ago. That's why I needed some help into implementing integration. – Steven Jul 27 '14 at 16:34
  • trying to learn two things at the same time is also massively error-prone. Concentrate on Java OR batch. – specializt Jul 27 '14 at 16:35
  • @specializt hi, i did think of using java i/o but then i wrote a batch script that has a lot of condition statement and commands related to some software. That's why I decided to use batch scripting but it is true that i did not consider about the integration part. Because I lack of knowledge in this area. – Steven Jul 27 '14 at 16:37
  • so your explanation basically is "i did it because i did it". Marvelous. – specializt Jul 27 '14 at 16:38
  • But regretting is no use. I am left with 1 week plus to do the integration. I did this for a project that I have to submit to my superior. I was wrong to have made the wrong decision at the initial stage. – Steven Jul 27 '14 at 16:39
  • @specializt I did it because of a voluntarily act since I also wanted to know more about java and batch script. – Steven Jul 27 '14 at 16:40

1 Answers1

0

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.

specializt
  • 1,913
  • 15
  • 26
  • But I couldn't run it. Is this able to run from thumbdrive? Or does it have to run it on the desktop? It says something like `Caused by java.io.IOException` blah blah blah. – Steven Jul 31 '14 at 07:34
  • "blah blah blah" is exactly your error-explanation. Learn to read error-messages. – specializt Jul 31 '14 at 08:50