Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can Anyone tell me how can I use Enum instead of "START" and "STOP"? I tried to make Enum with string (START("START")), but it turned out too complex. Is there any easy way to do it.

public void actionPerformed(ActionEvent e) {
        System.out.println(e.getActionCommand());
        if(e.getActionCommand() == "START") {
            this.sModel.paused = false;


        } else if(e.getActionCommand() == "STOP"){
            this.sModel.paused = true;

        }
share|improve this question

closed as off-topic by forsvarir, BCdotWEB, Mathias Ettinger, Heslacher, ferada Dec 1 at 9:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. After the question has been edited to contain working code, we will consider reopening it." – forsvarir, BCdotWEB, Mathias Ettinger, Heslacher, ferada
If this question can be reworded to fit the rules in the help center, please edit the question.

Leaving aside the enum concern, why wouldn't you do something like that ?

private static final String STOP = "STOP";
public void actionPerformed(ActionEvent e) {
    this.sModel.paused = e.getActionCommand() == STOP;
}

Then, would it still makes sense to have an enum ?

share|improve this answer
    
I did as you mentioned initially, but I need to do it with Enum as a part of an assignment. – Rafael Dec 1 at 7:48
    
Here is what I did, but it made it more complex when I tried to use it instead of "STOP", "START" /// START ("START"), STOP ("STOP"); String button; Buttons (String bu) { button = bu; } public String getString () { return this.button; } – Rafael Dec 1 at 7:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.