我使用 Jazzy Spell Library 创建了一个 EPub Spell Checker。问题是每当我运行我构建的项目时,拼写错误的单词应该出现在 JTable 中,但不会出现在 JTable 中。我尝试在 IDE 上运行该项目并且它可以工作。你认为是什么问题?
这是拼写检查的代码
private void btnSpellActionPerformed(java.awt.event.ActionEvent evt)
{
try {
this.setCursor(Cursor.WAIT_CURSOR);
File dic = new File(new File(strTmp,"dic"), cboDictionary.getSelectedItem().toString());
SpellDictionary dict = new SpellDictionaryHashMap(dic);
SpellProc p = new SpellProc();
DataCls dc = new DataCls();
dc.ExeComm("DROP TABLE IF EXISTS tblError;"
+ "CREATE TABLE tblError("
+ "FILE VARCHAR(255), "
+ "WORD VARCHAR(255), "
+ "LINE INT(10)"
+ ")");
String[] col = new String[]{"File","Word","Line"};
p.dtm.addColumn(col[0]);
p.dtm.addColumn(col[1]);
p.dtm.addColumn(col[2]);
for(int i = 0; i < lstFile.getSize(); i++) {
SpellChecker splChkr = new SpellChecker(dict);
spellCheck splChk = p.new spellCheck();
splChk.file = lstFile.getElementAt(i).toString();
splChk.counter = 0;
splChkr.addSpellCheckListener(splChk);
String toCheck = p.readXHTML(new File(lstFile.getElementAt(i).toString()));
splChkr.checkSpelling(new StringWordTokenizer(toCheck));
}
ResultSet rs = dc.ExeQuery("SELECT * FROM tblError");
try {
while (rs.next()) {
String cont[] = new String[rs.getMetaData().getColumnCount()];
for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
cont[i] = rs.getString(rs.getMetaData().getColumnName(i + 1).toString());
}
p.dtm.addRow(cont);
}
rs.close();
tblView.setModel(p.dtm);
}
catch (SQLException e) {
JOptionPane.showMessageDialog(rootPane, e);
}
JOptionPane.showMessageDialog(rootPane, "Spell checking completed.");
this.setCursor(Cursor.DEFAULT_CURSOR);
}
catch(FileNotFoundException e) {
JOptionPane.showMessageDialog(rootPane, "File loading error. \r\n\r\n" + e, "Error Occured.", JOptionPane.WARNING_MESSAGE);
}
catch(IOException f) {
JOptionPane.showMessageDialog(rootPane, "File loading error. \r\n\r\n" + f, "Error Occured.", JOptionPane.WARNING_MESSAGE);
}
}
这是 spellCheck() 的代码;
public class spellCheck implements SpellCheckListener {
String file = "";
String lst = "";
String[] rValue = {"","",""};
int counter;
String find = "";
DataCls dat = new DataCls();
@Override
public void spellingError(SpellCheckEvent svt) {
lst ="";
lstError.addElement(svt.getInvalidWord().replace("'", "\\'"));
try {
ResultSet rChk = dat.ExeQuery("SELECT MAX(LINE) FROM tblError WHERE FILE='" + new File(file).getName() + "'AND WORD='" + svt.getInvalidWord().replace("'", "''") + "'");
int rwCnt = 0;
while(rChk.next()) {rwCnt++;}
if (rwCnt == 0) {
try {
BufferedReader br = new BufferedReader(new FileReader(file));
int i = 0;
String line;
while((line = br.readLine()) != null) {
i++;
int index = line.indexOf(svt.getInvalidWord().replace("'", "\\'"));
if (index >= 0) {
dat.ExeComm("INSERT INTO tblError(FILE,WORD,LINE) "
+ "VALUES ('" + new File(file).getName() +"','" + svt.getInvalidWord().replace("'", "\\'") + "','" + i + "')");
break;
}
}
} catch (IOException e){
System.out.println(e);
}
} else if (rwCnt > 0){
ResultSet rs = dat.ExeQuery("SELECT MAX(LINE) FROM tblError WHERE FILE='" + new File(file).getName() + "' AND WORD='" + svt.getInvalidWord().replace("'", "''") + "'");
rs.next();
try {
int iline = rs.getInt(1);
try {
BufferedReader br = new BufferedReader(new FileReader(file));
int i = 0;
String line;
while((line = br.readLine()) != null){
i++;
int index = line.indexOf(svt.getInvalidWord().replace("'", "\\'"));
if (i > iline) {
if (index >= 0) {
dat.ExeComm("INSERT INTO tblError(FILE,WORD,LINE) "
+ "VALUES ('" + new File(file).getName() +"','" + svt.getInvalidWord().replace("'", "\\'") + "','" + i + "')");
break;
}
}
}
}
catch (IOException e) {
JOptionPane.showMessageDialog(null, e);
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex);
}
}
} catch (SQLException ex) {
JOptionPane.showConfirmDialog(null, ex);
}
}
}