1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
| import java.io.*;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Dialog;
import java.awt.FileDialog;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.*;
import javax.swing.JFrame;
public class gui extends Dialog implements MouseListener
{
String dfname = "project.txt", gridname = "project.txt" ;
int offset = 80, hmax =380 , vmax =180, downoffset = 40 + offset;
Button loadtriau, runjob;
boolean mesh=false;
TextField textfield0,textfield1,textfield2,textfield3,textfield4;
Label Q, US,UN,K1,K2 ;
String Q1="25000", US1="100", UN1="50",K11="1",K21="10";
//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("Loadmesh");this.add(loadtriau);
runjob = new Button("Run Job"); this.add(runjob);
Q = new Label("q =");
textfield0 = new TextField(Q1,20) ;
this.add(Q); this.add(textfield0);
US = new Label("us =");
textfield3 = new TextField(US1,20) ;
this.add(US); this.add(textfield3);
UN = new Label("us =");
textfield2 = new TextField(UN1,20) ;
this.add(UN); this.add(textfield3);
K1 = new Label("K1 =");
textfield1 = new TextField(K11,20);
this.add(K1); this.add(textfield1);
K2 = new Label("K2 =");
textfield4 = new TextField(K21,20);
this.add(K2); this.add(textfield4);
//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;
try{
FileOutputStream filename=
new FileOutputStream("/home/makarov/java/affichage.txt");
PrintStream ffile = new PrintStream(filename);
String cc= "/home/makarov/java/"+gridname;
ffile.println(cc);
}
catch(IOException Ex){
System.out.println("0-CA A FOIRE");
}
Runtime rt = Runtime.getRuntime();
try{
String line;
Process ax = rt.exec("/home/makarov/java/affichage.sh");
System.out.println("APRES L'EXECUTION");
try{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("1-CA A FOIRE");
}
}
catch(IOException Ex){
System.out.println("CA A FOIRE");
}
afficheMesh();
}
//principal P = new principal(400,400);
});
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("./exemple.sh");
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 afficheMesh(){
JFrame JF = new JFrame();
JF.setLayout(new BorderLayout());
principal P = new principal(300,300);
JF.setSize(300,300);
JF.add(P);
JF.setVisible(true);
//this.add(JF);
}
public void savemyparam()
{ String rhsval = textfield0.getText();
String temperval = textfield3.getText();
try{
FileOutputStream filename=
new FileOutputStream(dfname);
PrintStream ffile = new PrintStream(filename);
ffile.println(K11);
ffile.println(K21);
ffile.println(UN1);
ffile.println(US1);
ffile.println(Q1);
//if(checkbox0.getState()) ffile.println("0");
// else ffile.println("1");
if(mesh) ffile.println(gridname);
}
catch (IOException Ex)
{
System.out.println("2-CA A FOIRE");
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);
}
} |