tags:

views:

51

answers:

2

So I am trying to get my GUI to work. When I run the code below, it does nothing, and I'm sure I'm probably just doing something dumb, but I am completely stuck...

public void actionPerformed(ActionEvent e){
    UI.getInstance().sS++;

    if((UI.getInstance().sS %2) != 0){
        UI.getInstance().startStop.setName("STOP");
        UI.getInstance().change.setEnabled(false);
    }else if(UI.getInstance().sS%2 == 0){
        UI.getInstance().startStop.setName("START");
        UI.getInstance().change.setEnabled(true);
    }


}

public void setStartListener(StartHandler e){
    this.startStop.addActionListener(e);
}

sS is an int that increments every time the button startStop is clicked. change is also a button.

+1  A: 

Here's an example that shows a different approach to managing a Start/Stop button.

trashgod
+2  A: 

Hi, not really an answer, but I think your code would be simpler if you used a boolean instead of an int, something like:

public void actionPerformed(ActionEvent e){
    final boolean isEnabled = UI.getInstance().change.isEnabled();
    if(isEnabled){
        UI.getInstance().startStop.setName("STOP");
    }else{
        UI.getInstance().startStop.setName("START");
    }
    UI.getInstance().change.setEnabled(!isEnabled); 
}
Lucass