The disableButtonBool parameter of the toggleButton does nothing with the state of the button. I'd remove this parameter.
public final boolean toggleButton(final JButton buttonDisable, boolean disableButtonBool) {
buttonDisable.setEnabled(!buttonDisable.isEnabled()); // Swap button
// state
if (disableButtonBool) {
disableButtonBool = false;
} else {
disableButtonBool = true;
}
return disableButtonBool;// return Bool
}// //End ToggleButton method
I'd createmove the toggle method a ToggleButton class which(which would be a subclass of JButton for the toggle() method):
public class ToggleButton extends JButton {
private static final long serialVersionUID = 1L;
public ToggleButton(String text) {
super(text);
}
public boolean toggle() {
final boolean newState = !isEnabled();
setEnabled(newState);
return newState;
}
}
ItThen I'd use this class in the MoreSwing class:
private final ToggleButton nextButton = new ToggleButton("Next");
private final ToggleButton prevButton = new ToggleButton("Previous");
The toggle method belongs here, it manipulates the state of the button. (It increases cohesion.)
I'm not too familiar with Swing, but I think there should be a better way to stop the application than calling System.exit():
quitButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent event) {
System.exit(0);
}
});
I'm not too familiar with Swing, but I think there should be a better way to stop the application than calling System.exit():
quitButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent event) {
System.exit(0);
}
});
How to close a Java Swing application from the code
- I'd use JAXB for the XML processing.