这是我编的一个java编译器,在实现运行的操作的时候,文本区域text_r中没有任何显示,但是在执行编译操作的时候文本区域text_r出现结果,请高手指教一下,谢谢 
补充一下 
线程r_run是要实现运行操作的线程,错误就出现在那 
import java.awt.*; 
import java.awt.event.*; 
import java.io.*; class javaEdit extends Frame implements ActionListener,Runnable{ String file=null; 
String js=null; 
Thread c_run,r_run; 
MenuBar menubar=new MenuBar(); 
Menu menu_file=new Menu("文件"); 
Menu menu_run=new Menu("生成"); 
MenuItem item_new,item_open,item_save,item_exit,item_compiler,item_run; 
Label label_1=new Label("源文件"); 
Label label_2=new Label("输出"); 
TextArea text_t,text_r; 
Panel p1,p2; 
FileDialog open=new FileDialog(this,"打开",FileDialog.LOAD); 
FileDialog save=new FileDialog(this,"保存",FileDialog.SAVE); 
boolean mc=true; 
javaEdit(){ 
super("java文本编译器"); text_t=new TextArea("欢迎使用java编译器",30,10,TextArea.SCROLLBARS_BOTH); 
text_r=new TextArea(5,10); 
p1=new Panel(); 
p2=new Panel(); 
p1.setLayout(new GridLayout(2,1)); 
p2.setLayout(new GridLayout(2,1)); 
p1.add(label_1); p1.add(text_t); 
p2.add(label_2); p2.add(text_r); 
item_new=new MenuItem("新建"); 
item_open=new MenuItem("打开"); 
item_save=new MenuItem("保存"); 
item_exit=new MenuItem("退出"); 
item_compiler=new MenuItem("编译"); 
item_run=new MenuItem("运行"); 
menu_file.add(item_new); 
menu_file.add(item_open); 
menu_file.add(item_save); 
menu_file.add(item_exit); 
menu_run.add(item_compiler); 
menu_run.add(item_run); 
menubar.add(menu_file); 
menubar.add(menu_run); 
item_new.addActionListener(this); 
item_open.addActionListener(this); 
item_save.addActionListener(this); 
item_exit.addActionListener(this); 
item_compiler.addActionListener(this); 
item_run.addActionListener(this); 
open.addWindowListener(new WindowAdapter(){ 
public void windowClosing(WindowEvent e){ 
open.setVisible(false);}}); 
save.addWindowListener(new WindowAdapter(){ 
public void windowClosing(WindowEvent e){ 
save.setVisible(false);}}); 
setMenuBar(menubar); 
setSize(800,600); 
setVisible(true); 
setLayout(new GridLayout(2,1)); 
add(p1); add(p2); 
addWindowListener(new WindowAdapter(){ 
public void windowClosing(WindowEvent e){ 
System.exit(0);}}); 

public void actionPerformed(ActionEvent e){ if(e.getSource()==item_new){ 
text_t.setText(""); 
text_r.setText(""); } 
if(e.getSource()==item_open){ 
String s; 
open.setVisible(true); 
file=open.getDirectory()+open.getFile(); 
text_t.setText(""); 
setTitle(file); 
try{ 
FileReader in_file=new FileReader(file); 
BufferedReader in=new BufferedReader(in_file); 
while((s=in.readLine())!=null) 
text_t.append(s+´\n´); 
in.close(); 

catch(IOException er){} 

if(e.getSource()==item_save){ 
save.setVisible(true); 
file=save.getDirectory()+save.getFile(); 
try{ 
FileWriter out_file=new FileWriter(file); 
BufferedWriter out=new BufferedWriter(out_file); 
out.write(text_t.getText(),0,(text_t.getText()).length()); 
out.close(); 

catch(IOException er){} 

if(e.getSource()==item_exit){ 
System.exit(0); 

if(e.getSource()==item_compiler){ 
c_run=new Thread(this); 
c_run.start(); 

if(e.getSource()==item_run){ 
r_run=new Thread(this); 
r_run.start(); 


public void run(){ 
if(Thread.currentThread()==c_run){ 
text_r.setText(""); 
byte er[]=new byte[100]; 
int n; 
try{ Runtime ce=Runtime.getRuntime(); 
InputStream in=ce.exec("javac "+file).getErrorStream(); 
BufferedInputStream bin=new BufferedInputStream(in); 
while((n=bin.read(er,0,100))!=-1){ String sr=null; 
sr=new String(er,0,n); 
text_r.append(sr); 
if(sr!=null){mc=false;} 

if(mc) text_r.setText("编译完成无错误"); 

catch(IOException ex){} 

if(Thread.currentThread()==r_run){ 
byte rr[]=new byte[100]; 
String s=null; 
int n; 
js=file.substring(0,(file.length()-5)); 
text_r.setText(js); 
try{ 
Runtime ce=Runtime.getRuntime(); 
InputStream in=ce.exec("java "+js).getInputStream(); 
BufferedInputStream bin=new BufferedInputStream(in); 
while((n=bin.read(rr,0,100))!=-1){ 
s=new String(rr,0,n); 
text_r.append(s); 


catch(IOException e){} 

} public static void main(String agrs[]){ 
javaEdit go=new javaEdit(); 
} } 

解决方案 »

  1.   

    这不叫编译器把,这纯粹是命令行shell工作方式。仔细查查吧,错误在哪,没仔细看
      

  2.   

    看不懂!!!!不过现在还用awt有点.......swing耍哈嘛!!!
      

  3.   

    本人是初学者
    先用awt编一个,主要是想通过这个学习io
    本人检查很多次了,但是还是不知道哪里有错,没有编译异常
    就是在界面里点击运行的时候,没有输出结果.
    请高手进来指点一下
    谢谢了
      

  4.   

    我想再问一下
    如果我把程序写到某个目录下,比如是d:\test\text.java
    我在cmd下编译这个文件时javac d:\test\text.java 可以通过编译
    但是我要运行它的时候 java d:\test\text,就会出现错误,这是为什么?
    我的环境变量应该没有错误
    请高手指点一下
    谢谢
      

  5.   

    没仔细看~~调试了一下~~text_t.append(s+´\n´); 出错。
      

  6.   

    但是我要运行它的时候 java d:\test\text,就会出现错误,这是为什么?把你的运行错误贴出来啊
      

  7.   

    本公司为推广宣传公司产品,诚聘网络推广员。条件不限,只要家中有电脑,或者上班能上网的工作职员,会发邮件会利用QQ联系业务,宣传广告,信息发布,论坛发贴等方法宣传,有高额提成回报。可利用业余时间兼职,根据业绩每月最高可获报酬3000元左右。 详情请登陆:http://897288.com/?id=whui进入网站后可以点击网站上的“运作模式”,若有信心推广此网站,请联系每天8小时在线客服QQ:704757003。正式录用后赠送正版QQ好友群发软件和宣传资料。由于咨询者较多,请先看完网站内容后再做咨询,谢谢合作!