void (final JCheckBox first, final boolean firstState, final JCheckBox second, final boolean secondState) { ActionListener l = new ActionListener() { /** * One way check for the condition * @param checked the first to check * @param checkedState the state to match * @param changed the changed control * @param impliedState the implied state */ private static void check(final JCheckBox checked, final boolean checkedState, final JCheckBox changed, final boolean impliedState) { if (checked.isSelected() == checkedState) { changed.setSelected(impliedState); changed.setEnabled(false); } else { changed.setEnabled(true); } } /** * {@inheritDoc} */ @Override public void actionPerformed(ActionEvent e) { check(first, firstState, second, !secondState); check(second, secondState, first, !firstState); } }; first.addActionListener(l); second.addActionListener(l); l.actionPerformed(null); }