?? javacompiler.java
字號:
/*
* Created on 2004-5-27
*/
package yuchifang.javaIDE.compilers;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import javax.swing.JOptionPane;
import yuchifang.javaIDE.interfaces.ICompiler;
import yuchifang.javaIDE.interfaces.IExecCaller;
/**
* @author yuchifang
*/
public class JavaCompiler extends Thread implements ICompiler
{
private String exePath;
private String filePath;
private IExecCaller ec;
private JavaCompiler() { }
public JavaCompiler(String path)
{
exePath = path;
}
public void run()
{
synchronized(JavaCompiler.class)
{
ec.print("\r\n文件:[" + filePath + "]\r\n");
ec.print("------------------開始編譯[" + new Date() + "]------------------\r\n");
long interval = System.currentTimeMillis();
if (exePath == null)
{
int choice = JOptionPane.showConfirmDialog(
null,
"JDK配置出錯\r\n請先配置JDK!",
"JDK未配置",
JOptionPane.OK_OPTION); //##用null合適嗎?
return;
}
String[] args =
{
getExePath(),
filePath
};
ProcessBuilder pb = new ProcessBuilder(args);
pb.directory(new File(new File(filePath).getParent())); //有效嗎?
Process p = null;
try
{
p = pb.start();
} catch (IOException e)
{
e.printStackTrace();
return;
}
ec.printResults(p.getInputStream());
ec.printResults(p.getErrorStream());
interval = System.currentTimeMillis() - interval;
ec.print("\r\n------------------編譯結束["+ new Date() + "],耗時[" + interval/1000.0 + "]秒------------------\r\n");
}
}
public void compile(String filePath, IExecCaller ec)
{
this.filePath = filePath;
this.ec = ec;
start();
}
public void setExePath(String path)
{
exePath = path;
}
private String getExePath()
{
return exePath;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -