java的run代码 java runoob( 四 )


ErrorThread = new Thread(new RunTimeOutput(new InputStreamReader(pro getErrorStream())));
InPutThread start();
OutPutThread start();
ErrorThread start();
exec( javac + textField getText() + java );
Thread sleep( );
exec( java + textField getText() + );
} catch (Exception e) {
e printStackTrace();
}
}
});
button_ setText( 编译/运行 );
button_ setBounds( );
getContentPane() add(button_ );
}
public void FileOut(String name String Content) {
File file = new File(url + name);
if (file exists())
file delete();
try {
file createNewFile();
FileOutputStream out = new FileOutputStream(file);
byte buf[] = Content getBytes();
out write(buf);
out flush();
out close();
} catch (Exception ex) {
ex printStackTrace();
}
}
public class RunTimeInput implements Runnable {
private BufferedWriter bw = null;
public void run() {
bw = new BufferedWriter(new OutputStreamWriter(pro getOutputStream()));
while (true) {
try {
if (cmd != nullcmd length()) {
bw write(cmd + \n\n );
bw flush();
cmd = null;
}
Thread sleep( );
} catch (Exception e) {
e printStackTrace();
}
}
}
}
public class RunTimeOutput implements Runnable {
InputStreamReader isr = null;
public RunTimeOutput(InputStreamReader is) {
isr = is;
}
private BufferedReader br = null;
public void run() {
br = new BufferedReader(isr);
while (true) {
try {
String s = br readLine();
if (s != null) {
textArea setText(textArea getText() + \n + s);
textArea setSelectionStart(textArea getText() length());
}
Thread sleep( );
} catch (Exception e) {
e printStackTrace();
}
}
}
}
public void exec(String Content) {
cmd = Content;
}
public String getName(String str) {
String name = ;
if (str indexOf( class ) != ) {
String[] s = str split( \\s+ );
for (int i = ; is length; i++) {
if (s[i] equals( class )) {
if ((i + )s length)
name = s[i + ];
int a = ;
if((a=name indexOf( { ))!= ){
name= name substring( a);
}
}
}
}
return name;
}
public void OutputData() {
try {
FileOutputStream out = new FileOutputStream(file);
byte buf[] = textArea_ getText() getBytes();
out write(buf);
out flush();
out close();
} catch (Exception e) {
e printStackTrace();
}
}
public void InputData() {
try {
FileInputStream in = new FileInputStream(file);
int a = (int)file length();
byte buf[] = new byte[a];
int len = in read(buf);
if (len == ){
System out println( 文件为空 );
}else{
textArea_ setText(new String(buf len));
}
} catch (Exception e) {
e printStackTrace();
}
}
/**
* @param str 内容
* @param col 颜色
* @param bold 是否粗体
* @param fontSize 字体大小
*/
public void setDocs(String str Color col boolean bold int fontSize) {
SimpleAttributeSet attrSet = new SimpleAttributeSet();
StyleConstants setForeground(attrSet col);
// 颜色
if (bold == true) {
StyleConstants setBold(attrSet true);
}// 字体类型
StyleConstants setFontSize(attrSet fontSize);
// 字体大小
Document doc = textArea_ getDocument();
try {
doc insertString(doc getLength() str attrSet);
} catch (BadLocationException e) {
System out println( BadLocationException: + e);
}

推荐阅读