0

For some background: I've been working on a swing application (yes, I'm aware that it's outdated - leave me be) that lets you write then compile a file, and should output the result of the main of said file in a JTextArea Terminal. Now, I've gotten the JTextArea to act as the output (the System.out) but I can't get it to accept input. i saw another question that was similar, linked here, and it says to just run myclass.main, but I don't understand it and it's old, so I can't reply. How would one best go about this?

my compilation code:

//This creates a file
public void createAndRun(String fileName, String text){
        System.out.println("File: " + fileName);
        File file;
        try{
            file = new File((fileName + ".java"));
            FileWriter writer = new FileWriter(file);
            writer.write(text);
            writer.close();
        }catch(IOException e){
            e.printStackTrace();
        }
        try{
            runProcess("javac "+fileName+".java");
            runProcess("java "+fileName);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
//This just runs a process to make the above code easier to read
private static void runProcess(String command) throws Exception{
        Process pro;
        pro = Runtime.getRuntime().exec(command);
        pro.waitFor();
        System.out.println(command + " exitValue(): " + pro.exitValue());
    }

To be Clear: It can run any file that only deals with printing lines of code. That is not an issue. The issue is input. Any help would be greatly appreciated.

dawis11
  • 820
  • 1
  • 9
  • 24
Oct. Lips
  • 97
  • 1
  • 10

0 Answers0