Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
Source Link
added 365 characters in body
Source Link
palacsint
  • 30.3k
  • 9
  • 82
  • 157
  1. 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
    
  2. 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.)

  1. 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);
     }
    });
    
  1. 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

  1. I'd use JAXB for the XML processing.
  1. 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
    
  2. I'd create a ToggleButton class 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;
     }
     }
    

It increases cohesion.

  1. 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

  1. 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
    
  2. I'd move the toggle method a ToggleButton class (which would be a subclass of JButton):

     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.)

  1. 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);
     }
    });
    
  1. I'd use JAXB for the XML processing.
Source Link
palacsint
  • 30.3k
  • 9
  • 82
  • 157
Loading
default

AltStyle によって変換されたページ (->オリジナル) /