У меня 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