如何在一个自定义窗口中显示(文本区域)显示在DOS下运行JAVAC\JAVA时所触发的异常?

03-04-01 SUNBOYJAVA

如:

//Jtoc.java

import java.awt.event.*;

import javax.swing.*;

public class Jtoc extends JFrame implements ActionListener

{

JTextField javaname = new JTextField(15);

JButton javabutton = new JButton("编译");

JTextField classname = new JTextField(15);

JButton classbutton = new JButton("运行");

JTextArea messagetext = new JTextAea(5,20);

String javastring; boolean jtoc = false;

public Jtoc()

{

super("JavaToClass");

setSize(250,210);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

classbutton.setEnabled(false);

JPanel pane = new JPanel();

javabutton.addActionListener(this);

classbutton.addActionListener(this);

pane.add(javaname); pane.add(javabutton);

pane.add(classname); pane.add(classbutton);

pane.add(messagetext);

setContentPane(pane);

}

public static void main(String[] args)

{

Jtoc jtc = new Jtoc();

jtc.show();

}

public void actionPerformed(ActionEvent evt)

{

Object src = evt.getSource();

javastring =javaname.getText();

Runtime r = Runtime.getRuntime();

Process p = null;

if (src==javabutton && !(javastring.equals("")))

{ String getjavastra ="javac "+javastring+"java";

try{

p=r.exec(getjavastra);

p.waitFor();

classbutton.setEnabled(true);

classname.setText(javastring);

jtoc = true;

}catch(Exception e)

{messagetext.setText

("Error:"+e.getMessage());

}

}

else if (src==classbutton && jtoc==true)

{

String getjavastrb="java "+javastring;

try{

p=r.exec(getjavastrb)

p.waitFor();

}catch(Exception e)

{messagetext.setText("Error:"+e.getMessage());

}

}

}

}

信息框中不能显示出错时有关异常返回信息 该如何解决啊?

我如何能让信息框中显示出错时在DOS下返回的异常信息?

谢谢