一個字符串我有一個的DocumentListener尋找JTextField中的任何改變:不斷閱讀從JTextField中
public class MyDocumentListener implements DocumentListener {
static String text;
public void insertUpdate(DocumentEvent e) {
updateLog(e);
}
public void removeUpdate(DocumentEvent e) {
updateLog(e);
}
public void changedUpdate(DocumentEvent e) {
//Plain text components do not fire these events
}
public static String passText() {
System.out.println("string that will be passed is: "+text);
return text;
}
public void updateLog(DocumentEvent e) {
Document doc = (Document)e.getDocument();
int length = e.getLength();
try {
text = doc.getText(0, length);
} catch (BadLocationException e1) {
e1.printStackTrace();
}
System.out.println("you typed "+text);
}
}
,然後在其他類:
String info = MyDocumentListener.passText();
的問題是我只有一個字符,而不是整個字符串。有什麼建議麼?
很簡單的;) – Hurdler 2012-02-21 19:00:43