The
disableButtonBool
parameter of thetoggleButton
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 aToggleButton
class which(which would be a subclass ofJButton
for thetoggle()
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.
The
disableButtonBool
parameter of thetoggleButton
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 create a
ToggleButton
class which would be a subclass ofJButton
for thetoggle()
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; } }
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); } });
The
disableButtonBool
parameter of thetoggleButton
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 move the
toggle
method aToggleButton
class (which would be a subclass ofJButton
):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; } }
Then 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'd use JAXB for the XML processing.