import java.awt.*; import java.io.*; public class applic extends Frame { public applic() { setTitle("Generic Project"); TextIn = new TextArea(10, 50); TextOut = new TextArea(10, 50); TextOut.setEditable(false); add("East", TextOut); add("West", TextIn); Panel p = new Panel(); p.setLayout(new FlowLayout()); p.add(Open = new Button("Open input file")); p.add(Save = new Button("Save input file")); p.add(Run = new Button("Run Demeter/Java")); p.add(Clear = new Button("Reset windows")); p.add(Close = new Button("Exit application")); add("South", p); } public boolean handleEvent(Event evt) { if (evt.id == Event.WINDOW_DESTROY) System.exit(0); // if (evt.id == Event.WINDOW_MOVED) { // Dimension d = this.size(); // System.out.println(d.width + " " + d.height); } else return super.handleEvent(evt); return true; } public boolean action(Event evt, Object arg) { if (evt.target == Open) OpenFile(); else if (evt.target == Save) SaveFile(); else if (evt.target == Run) RunDemeter(); else if (evt.target == Clear) { TextIn.setText(""); TextOut.setText(""); filename = null; } else if (evt.target == Close) System.exit(0); else return super.action(evt, arg); return true; } public void OpenFile() { FileDialog d = new FileDialog(this, "File Dialog", FileDialog.LOAD); d.setDirectory(path); d.show(); filename = d.getFile(); if (filename != null) { dirname = d.getDirectory(); try { DataInputStream in = new DataInputStream(new FileInputStream(dirname + filename)); String line = in.readLine(); TextIn.setText(""); while(line != null) { TextIn.appendText(line + "\n"); line = in.readLine(); } in.close(); System.out.println("The file has been read in"); } catch(Exception e) { } } } public void SaveFile() { FileDialog d = new FileDialog(this, "File Dialog", FileDialog.SAVE); d.setDirectory(path); d.show(); dirname = d.getDirectory(); filename = d.getFile(); if (filename != null) { try { PrintStream out = new PrintStream(new FileOutputStream(dirname + filename)); out.println(TextIn.getText()); out.close(); System.out.println("The file has been saved"); } catch(Exception e) { } } } public void RunDemeter() { if (filename == null) { if (TextIn.getText().length() == 0) OpenFile(); else SaveFile(); } if (filename == null) return; String command = path + "myscript " + dirname + filename; try { Process p = Runtime.getRuntime().exec(command); p.waitFor(); PasteOutput(); } catch(Exception e) { System.out.println("Error running Demeter/Java"); } } public void PasteOutput() { try { DataInputStream in = new DataInputStream(new FileInputStream("created.out.beh")); String line = in.readLine(); TextOut.setText(""); while(line != null) { TextOut.appendText(line + "\n"); line = in.readLine(); } in.close(); } catch(Exception e) { } } public static void main(String[] args) { Frame f = new applic(); f.resize(900,570); f.show(); } private Button Open, Save, Run, Clear, Close; private String filename = null, dirname; private String path = "/proj/demsys/com1205/w97/alex/project/phase3/"; private TextArea TextIn, TextOut; private Runtime dem, dem1; private Process proc; }