I need your help. I have a C executable called “generator.out” that is a main() function that receives int argc and char * argv[]. The arguments for this main function are a file (let’s call it sample.da) and a target file (let’s call it out.bn). I need to create a java interface that can read those names (sample.da and out.bn) and run my function. The code I have so far is:
package swingapps;
import javax.swing.*;
import java.awt.Dimension;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import java.lang.*;
public class Swingapps {
private JButton button = new JButton("Generate Bayesian Network");
private JTextField path=new JTextField(40);
private JTextField name=new JTextField(40);
public Swingapps(JPanel jp) {
jp.add(button);
jp.add(path);
jp.add(name);
button.addActionListener(new Handler());
path.addActionListener(new Read());
name.addActionListener(new Call());
}
String text;
private class Read implements ActionListener {
public void actionPerformed(ActionEvent evt) {
text = path.getText();
path.selectAll();
}
}
String namet;
private class Call implements ActionListener {
public void actionPerformed(ActionEvent evt) {
namet = name.getText();
path.selectAll();
}
}
File filep=new File("text"+File.separator+"text");
File filen=new File("namet"+File.separator+"namet");
private class Handler implements ActionListener {
public void actionPerformed(ActionEvent e) {
try {
Process p= Runtime.getRuntime().exec("/home/user/workspace/proj2/./generator.out");
}
catch(IOException ioex)
{
ioex.printStackTrace();
}
}
}
public static void main(String[] args) {
JFrame frame = new JFrame("Contador ");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p = new JPanel();
frame.setContentPane(p);
p.setLayout(new BoxLayout(p,BoxLayout.Y_AXIS));
Swingapps app = new Swingapps(p);
frame.pack();
frame.setVisible(true);
}
}
Please note that I’m a newbie in java so I don’t understand very much of this. I just need a simple interface to run this program!
Thank you very much!
Take a look at ProcessBuilder class, here’s an example that could fit your situation :