?? example111.java
字號:
import java.awt.*;
import java.io.*;
import java.awt.event.*;
public class Example111
{ public static void main(String args[])
{JDK f=new JDK();
}
}
class JDK extends Frame implements ActionListener,Runnable
{ Thread compiler=null;
Thread run_prom=null;
boolean bn=true;
CardLayout mycard;
Panel p=new Panel();
File file_saved=null;
TextArea input_text=new TextArea(),
compiler_text=new TextArea(),
dos_out_text= new TextArea();
Button button_input_text,button_compiler_text,
button_compiler,button_run_prom,button_see_doswin;
TextField input_file_name_text=new TextField("輸入編譯的文字.java");
TextField run_file_name_text=new TextField("輸入應(yīng)用程序主類的名字");
JDK()
{super("Java 編程小程序");
mycard=new CardLayout();
compiler= new Thread(this);
run_prom=new Thread(this);
button_input_text=new Button("程序輸入?yún)^(qū)");
Button button_compiler_text =new Button("編譯結(jié)果區(qū)");
button_compiler= new Button("編譯程序");
button_run_prom=new Button("運行應(yīng)用程序");
button_see_doswin=new Button("查看流System輸入的信息");
p.setLayout(mycard);
p.add("input",input_text);
p.add("compiler",compiler_text);
p.add("dos",dos_out_text);
add(p,"Center");
add(button_see_doswin,"South");
compiler_text.setBackground(Color.pink);
Panel p1=new Panel();
p1.setLayout(new GridLayout(4,2));
p1.add(new Label("輸入程序: "));
p1.add(button_input_text);
p1.add(new Label("翻譯結(jié)果:"));
p1.add(button_compiler_text);
p1.add(input_file_name_text);
p1.add(button_compiler);
p1.add(run_file_name_text);
p1.add(button_run_prom);
add(p1,BorderLayout.NORTH);
button_input_text.addActionListener(this);
button_compiler_text.addActionListener(this);
button_compiler.addActionListener(this);
button_run_prom.addActionListener(this);
button_see_doswin.addActionListener(this);
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);
}
});
setBounds(100,120,700,360);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==button_input_text)
{ mycard.show(p,"input");
}
else if(e.getSource()==button_compiler_text)
{mycard.show(p,"compiler");
}
else if(e.getSource()==button_see_doswin)
{ if(!(compiler.isAlive()))
{compiler=new Thread(this);
}
try{compiler.start();}
catch(Exception eee){}
mycard.show(p,"compiler");
}
else if (e.getSource()==button_run_prom)
{ if(!(run_prom.isAlive()))
{run_prom=new Thread(this);
}
try{run_prom.start();
}
catch(Exception eee){}
mycard.show(p,"dos");
}
}
public void run()
{ if(Thread.currentThread()==compiler)
{compiler_text.setText(null);
String temp=input_text.getText().trim();
byte buffer[]=temp.getBytes();
int b=buffer.length;
String file_name=input_file_name_text.getText().trim();
try{ file_saved=new File(file_name);
FileOutputStream writefile=new FileOutputStream(file_saved);
writefile.write(buffer,0,b);
writefile.close();
}
catch(IOException e5)
{System.out.println("Erro ");
}
try{Runtime ce=Runtime.getRuntime();
InputStream in=ce.exec("javac"+file_name).getErrorStream();
BufferedInputStream bin=new BufferedInputStream(in);
byte shuzu[]=new byte[100];
int n;boolean bn=true;
while((n=bin.read(shuzu,0,100))!=-1)
{ String s=null;
s=new String(shuzu,0,n);
compiler_text.append(s);
if(s!=null)bn=false;
}
if(bn)
{compiler_text.append(" 編譯正確");
}
}
catch(IOException e1){}
}
else if (Thread.currentThread()==run_prom)
{dos_out_text.setText(null);
try{ Runtime ce=Runtime.getRuntime();
String path= run_file_name_text.getText().trim();
InputStream in =ce.exec("java"+path).getInputStream();
BufferedInputStream bin=new BufferedInputStream(in);
byte zu[]=new byte[150];
int m;String s=null;
while((m=bin.read(zu,0,150))!=-1)
{ s= new String(zu,0,m);
dos_out_text.append(s);
}
}
catch(IOException e1){}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -