import java.io.*; import java.lang.Runtime; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class IDE2 extends JFrame { private JButton compileButton; private JTextArea errorText; private JScrollPane errorScrollPane; public static void main ( String args[]) { IDE2 ide = new IDE2(); WindowAdapter windowAdapter = new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } }; ide.addWindowListener( windowAdapter ); } public IDE2() { show(); Container container = getContentPane(); container.setLayout( new FlowLayout() ); errorText = new JTextArea(20,40); compileButton = new JButton("Compile"); errorScrollPane = new JScrollPane(errorText); compileButton.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) { Compile(getFileName("File to compile?")); ShowResults(); } }); container.add(compileButton); container.add(errorScrollPane); setSize( 500, 600 ); show(); } private void Compile(String fileName) { Runtime runtime = Runtime.getRuntime(); Process process; String[] command = new String[3]; command[0] = "cmd"; command[1] = "/c"; command[2] = "javac " + fileName + " 2> err.out"; try { process = runtime.exec(command); try { process.waitFor(); } catch (InterruptedException interruptedE) { System.err.println("Compile was interrupted"); } } catch (IOException exception) { System.out.println(exception.toString()); } } private String getFileName(String title) { String fileName; FileDialog fileDialog = new FileDialog(this, title, FileDialog.LOAD); fileDialog.setFile("*.java"); fileDialog.show(); fileName = fileDialog.getDirectory() + fileDialog.getFile(); return fileName; } private void ShowResults() { String line; errorText.selectAll(); errorText.cut(); try { FileInputStream errorFile = new FileInputStream( "err.out" ); BufferedReader errorBuffer = new BufferedReader(new InputStreamReader(errorFile)); while( ( errorBuffer.ready() )) { line = errorBuffer.readLine(); if ( errorBuffer != null ) { errorText.append(line); errorText.append("\n"); } } if (errorText.getText().length() == 0) { errorText.append("Compiled with no errors..."); } } catch (FileNotFoundException Exception) { System.out.println( "File Not Found" ); } catch (IOException Exception) { System.out.println( "IO Exception" ); } } }