public void actionPerformed(ActionEvent e)
{
String sout;
try
{
if(e.getSource()==compile)
{
sout=input.getText();
Runtime rt=Runtime.getRuntime();
Process p=rt.exec("javac sout.java",null,new File("C:/c/compile assign"));
}
我将类名存储在 String sout(通过 TextField)中,然后调用 sout.java(即 classname.java),但它无法构建类文件。
if(e.getSource()==run)
{
InputStream is = Runtime.getRuntime().exec("java input.getText()",null,new File("C:/c/compile assign")).getInputStream();
//BufferedInputStream b=new BufferedInputStream(is);
BufferedReader br= new BufferedReader(new InputStreamReader(is));
output.setText(br.readLine()+"hello");
}
}
catch(Exception e1)
{
e1.printStackTrace();
}
}