/**
* Your application code goes here
*/
package userclasses;
[…]
/**
* State machine for the maths app
*
* @author Ahmet Ekrem Saban
* @since 2014-08-15
*/
public class StateMachine extends StateMachineBase {
/**
* The field that says to calculate the combination of
* the string characters.
*/
private boolean combine;
/** The button group for the two radio buttons. */
private ButtonGroup radioButtons;
[…]
/**
* Decides whether to calculate the combination or permutation of the
* input string.
*/
private void determineRadioButtonState() {
final RadioButton combineRadioButton = findCombineRadioButton();
final RadioButton permutateRadioButton = findPermutateRadioButton();
if (radioButtons != null && radioButtons.getButtonCount() == 0) {
radioButtons.add(combineRadioButton);
radioButtons.add(permutateRadioButton);
printState(combineRadioButton, permutateRadioButton);
combineRadioButton.pressed();
printState(combineRadioButton, permutateRadioButton);
permutateRadioButton.pressed();
printState(combineRadioButton, permutateRadioButton);
}
final boolean isCombination = combineRadioButton.isSelected();
final boolean isPermutation = permutateRadioButton.isSelected();
combine = (isCombination || !isPermutation) ? false : true;
}
/**
* Prints the state of the given buttons
* @param radioButtons
*/
private void printState(final RadioButton... radioButtons) {
if (radioButtons != null) {
for (final RadioButton radioButton : radioButtons) {
System.out.println("printState" + "combineRadioButton is "
+ ((radioButton.isSelected()) ? "" : "not ") + "pressed.");
}
}
}
/**
* This method should be used to initialise variables instead of
* the constructor/class scope to avoid race conditions
*
* @param resource
*/
@Override
protected void initVars(final Resources resource) {
combine = true;
radioButtons = new ButtonGroup();
}
[…]
}