?? operate.java
字號:
package operation;
import java.io.IOException;
import entity.*;
import file.*;
//完成所有操作
public class Operate {
private Dictionary[] dictionary; // 儲存字典
private String filename; // 文件名
private int dicnumber; // 字典數目
private int dicNO; // 當前字典號
private Word[] error; // 錯誤單詞
private int errornumber; // 錯誤單詞數
private String errorinfo; // 錯誤信息
// 構造函數 最多生成10本字典
public Operate() {
dictionary = new Dictionary[10];
}
// 獲取文件名
public String getFilename() {
return filename;
}
// 獲取錯誤信息
public String getErrorinfo() {
return errorinfo;
}
// 獲取錯誤單詞
public Word[] getError() {
return error;
}
// 獲取錯誤單詞數目
public int getErrornumber() {
return errornumber;
}
// 設置使用的字典
public void setDicNO(int dicNO) {
this.dicNO = dicNO;
}
// 生成新字典 返回字典名
// pathname 字典路徑
public String createDictionary(String pathname) throws IOException {
if (dicnumber > 9) {
return null;
}
DictionaryFactory df = new DictionaryFactory();
dictionary[dicnumber] = df.createDictionary(pathname);
dicnumber++;
return dictionary[dicnumber - 1].getName();
}
// 檢查文本
// text 要檢查的文本 filename 文件名
public void checkString(String text, String filename) {
int wordlength = 0;
WordsFactory wf = new WordsFactory();
CheckText ct = new CheckText();
Word[] words;
words = wf.createWordsFromString(text); // 分析文本
wordlength = wf.getWordamount(); // 獲取單詞長度
error = ct.errorWords(words, wordlength, dictionary[dicNO]); // 記錄錯誤單詞
errornumber = ct.getErrornumber(); // 記錄錯誤單詞數目
}
// 保存錯誤信息
public void saveError() {
ErrorToString ets = new ErrorToString();
errorinfo = ets.infoToString(filename, dictionary[dicNO].getName(),
error, errornumber); // 記錄錯誤信息
}
// 讀入文件
// pathname 文件路徑 讀文件失敗 拋出異常IOException
public String readFile(String pathname) throws IOException {
ReadFile rf = new ReadFile(pathname);
filename = rf.getFileName();
return rf.read();
}
// 保存信息
// pathname 保存路徑 寫文件失敗 拋出異常IOException
public void saveString(String pathname) throws IOException {
WriteFile wf = new WriteFile(pathname);
wf.write(errorinfo);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -