I have a project in which i have to enable and disable the use of buttons (addRn, addSw, and addCy) with setEnabled(). I have tried many things including adding a documentListener but I am getting too confused. Does anyone have an idea what to do?
ArrayList<JTextField> run = new ArrayList<>();
run.add(intervals);
run.add(minRest);
ArrayList<JTextField> swim = new ArrayList<>();
swim.add(intervals);
swim.add(minRest);
swim.add(loc);
ArrayList<JTextField> cycle = new ArrayList<>();
cycle.add(tempo);
cycle.add(terrain);
DocumentListener listener = new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
changedUpdate(e);
}
@Override
public void insertUpdate(DocumentEvent e) {
changedUpdate(e);
}
@Override
public void changedUpdate(DocumentEvent e) {
boolean canEnable = true;
for (JTextField intervals : run) {
intervals.getDocument().addDocumentListener(listener);
if (intervals.getText().isEmpty()) {
canEnable = false;
}
}
for (JTextField minRest : run) {
if (minRest.getText().isEmpty()) {
canEnable = false;
}
}
addRn.setEnabled(canEnable);
}
};
this is what I have so far, but i feel like there is quite a bit missing and I am not familiar enough to find the problem. I tried to approach it as was suggested here