All pastes #611327 Raw Edit

Mine

public java v1 · immutable
·published 2007-07-09 21:35 UTC
rendered paste body
/* * Class JAVAForm :- Represents a simple form in java * * Created on 03 July 2007, 22:45 */package org.waitch11.transformer.translator.JAVA;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileWriter;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import org.waitch11.transformer.translator.FormInterface;/** * * @author William */public class JAVAForm implements FormInterface{        /** Creates a new instance of JAVAForm */    public JAVAForm() {    }        /**     * Method outputFormCode :- outputs the form code     *     * @return String out     * @param String className, String instantiations, String definitions, String addToForm, String variableDefinitions     */    public String outputFormCode(String className, String instantiations, String definitions, String addToForm, String variableDefinitions){                //set out        String out = "";        out += "public class " + className + " extends javax.swing.JFrame { \n";        out += "public "+className +"() { \n";        out += "initComponents(); \n";        out += "} \n";        out += "private void initComponents() { \n";        out += "" + instantiations + " \n";        out += "getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); \n";        out += "setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); \n";        out += "" + definitions + "\n";        out += "pack();\n";        out += "}\n";        out += "public static void main(String args[]) {\n";        out += "java.awt.EventQueue.invokeLater(new Runnable() {\n";        out += "public void run() { \n";        out += "new "  +className + "().setVisible(true); \n";        out += "} \n";        out += "}); \n";        out += "} \n";        out += "" + variableDefinitions +  " \n";        out += "} \n";                //return out        return out;    }        /**     * Method writeFile :- writes the file     *     * @param String outFile, String out     */    public void writeFile(String outFile, String out){        try {            // Create temp file.            File dir = new File("C:\\JavaOutput\\"+outFile + ".java");                        // Write to temp file            BufferedWriter outB = new BufferedWriter(new FileWriter(dir));            outB.write(out);            outB.close();            this.changeDir();            this.complieFile(dir);            this.runFile(dir);        } catch (IOException e) {            e.printStackTrace();        }    }        /**     * Method compileFile :- complies the file     *     * @param File file     */    public void complieFile(File file){        try {                        String cmd;               cmd = "javac " + file.getName();            System.out.println(cmd);            Process child = Runtime.getRuntime().exec(cmd);                                InputStream lsOut = child.getInputStream();            InputStreamReader r = new InputStreamReader(lsOut);            BufferedReader in = new BufferedReader(r);                    } catch (IOException e) {            System.out.println("Compile Command failed!");            e.printStackTrace();        }    }        /**     * Method runFile :- runs the file     *     * @param File file     */    public void runFile(File file){        try {                        String[] parts = file.getName().split(".");            String name = parts[0].trim();            System.out.print("Name : " + name);            // Execute a command without            String cmd;            cmd = "java " + name;            System.out.println(cmd);            Process child = Runtime.getRuntime().exec(cmd);                    } catch (IOException e) {            System.out.println("run failed!");            e.printStackTrace();        }    }        public void changeDir(){        try {                        String cmd;            cmd = "cd c:\\JavaOutput\\";            System.out.println(cmd);            Process child = Runtime.getRuntime().exec(cmd);                        InputStream lsOut = child.getInputStream();            InputStreamReader r = new InputStreamReader(lsOut);            BufferedReader in = new BufferedReader(r);                    } catch (IOException e) {            System.out.println("Compile Command failed!");            e.printStackTrace();        }    }}