Bonjour,
Je commence à programmer en C++. J'ai écrit un programme Java, et je lance un programme C++. Ma question est la suivante une fois les variables définies dans l'interface Java, quelle écriture dans le programme Java va permettre de recopier ces valeurs dans le programme C++
Ci-joint mon programme.
Je vous remercie par avance.
import java.awt.*; //file gui.java
import java.io.*;
import java.awt.event.*;
public class gui extends Dialog implements MouseListener
{
String dfname = "project.txt", gridname ;
int offset = 80, hmax =380 , vmax =180, downoffset = 40 + offset;
Button loadtriau, runjob;
boolean mesh=false;
TextField textfield0,textfield1,textfield2,textfield3;
Label rhs, temper ;
String rhsval="x+y", temperval="200";
Checkbox checkbox0, checkbox1;
CheckboxGroup pbcheckboxes;
int dwhat0=1;
public gui(Frame parent) {
super(parent, "Project Data Input Interface", false);
this.setSize(hmax+2*offset, vmax+4*offset);
}
public class getfilename extends Frame{
FileDialog fd;
public String fname;
public getfilename() { }
public String getthename(){
fd = new FileDialog(this, "Choose a mesh",FileDialog.LOAD);
fd.setVisible(true);
fname = fd.getFile();
return fname;
}
}
public void myinterface(){
this.setLayout(new FlowLayout());
loadtriau = new Button("Load Mesh");this.add(loadtriau);
runjob = new Button("Run Job"); this.add(runjob);
rhs = new Label("f =");
textfield0 = new TextField(rhsval,20) ;
this.add(rhs); this.add(textfield0);
temper = new Label("rho =");
textfield3 = new TextField(temperval,20) ;
this.add(temper); this.add(textfield3);
pbcheckboxes = new CheckboxGroup();
checkbox0 = new Checkbox("Explicite",pbcheckboxes,dwhat0==1);
checkbox1 = new Checkbox("Implicit",pbcheckboxes,dwhat0==0);
this.add(checkbox0);
this.add(checkbox1);
this.pack();
Graphics g = this.getGraphics();
loadtriau.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
getfilename ff = new getfilename();
gridname = ff.getthename();
mesh = true;
}
});
runjob.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
savemyparam();
String line;
Runtime rt = Runtime.getRuntime();
try{
System.out.println("exec : on lance la partie C++");
Process ax = rt.exec("./a.out");
InputStream ao = ax.getInputStream() ;
BufferedReader br = new BufferedReader(new InputStreamReader(ao));
while (( line= br.readLine()) != null) {
System.out.println(line);
}
}
catch (IOException Ex){
System.out.println("catch execption exec ");
System.out.println(Ex.getMessage());
System.exit(1);
}
System.out.println(" Exit normal ");
System.exit(0);
}
});
this.addMouseListener(this);
addMouseListener(this);
}
public void savemyparam()
{ String rhsval = textfield0.getText();
String temperval = textfield3.getText();
try{
FileOutputStream filename=
new FileOutputStream(dfname);
PrintStream ffile = new PrintStream(filename);
ffile.println(rhsval);
ffile.println(temperval);
if(checkbox0.getState()) ffile.println("0");
else ffile.println("1");
if(mesh) ffile.println(gridname);
}
catch (IOException Ex)
{
System.out.println(Ex.getMessage());
}
}
public void paint( Graphics g ) {;}
public void mousePressed(MouseEvent e) {;}
public void mouseReleased(MouseEvent e){;}
public void mouseEntered(MouseEvent e) {;}
public void mouseClicked(MouseEvent e) {;}
public void mouseExited(MouseEvent e) {;}
public static void main(String[] args){
Frame f = new Frame("Java Project Interface");
gui b = new gui(f);
b.myinterface();
b.setSize(840,300);
b.setVisible(true);
}
}