This line
setJPanel(ciphertextArray, panel3, "1");
also adds a DocumentListener
to every element of the ciphertextArray
TextField
. So every time the value of one of your cipher text TextField
s changes, the method setCipherText()
is invoked.
This leads to the following sequence:
- You enter a new value in one of the
TextField
s ofarrayIV
orplainTextArray
setCipherText()
is invokedsetCipherText()
changes the value of a cipher textTextField
setCipherText()
is again invoked (explanation above). Go back to 2.
Thats why you get the IllegalStateException
.
So the solution is to do NOT add a DocumentListener
to the TextFields
in your ciphertextArray
.
Solution could be implemented as follows:
public void setJPanel(JTextField array[], JPanel container, String s, boolean docListener) {
for (int i = 0; i < 8; i++) {
array[i] = new JTextField(s, 4);
if (docListener) {
array[i].getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent de) {
setCiphertext();
}
@Override
public void removeUpdate(DocumentEvent de) {
setCiphertext();
}
@Override
public void changedUpdate(DocumentEvent de) {
setCiphertext();
}
});
}
container.add(array[i]);
}
}
[...]
setJPanel(arrayIV, panel1, "1a", true);
setJPanel(plaintextArray, panel2, "1b", true);
setJPanel(ciphertextArray, panel3, "1", false);