Text changes on label with switch

0

Do you know that initial Pokemon conversation?

  

"Welcome to the pokemon world" - ENTER
  "Are you a girl or a boy?" -ENTER
  CONTINUE ....

So, I'm trying to do one through Java swing, at the moment it looks like this:

private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        jLabel1.setText(mudarTexto());
        //i++;
    }                                    


    public String mudarTexto(){
            //jTexto.setText("Olá,bem vindo ao mundo pokémon");
            int i = 0;
            switch(i){
                case 0:
                    c ="oi";
                case 1:
                    c  =  "Olá,bem vindo ao mundo pokémon";
                case 2:
                    c = "Você é garoto ou garota?";
                case 3:
                    c = "aa";
                default:
                    c = "c";

            }

            return c ;
    }

But switch does not read my i as zero, it only starts the last switch statement that in the case is default, if the last one was case 3, then it would be printed, how can I solve this problem ?

    
asked by anonymous 29.05.2016 / 02:12

1 answer

2

This happens because you are not leaving switch when you find the case correct, so it goes through all of them. Change by adding the "stops" between cases:

switch(i){
    case 0:
        c ="oi";
        break;
    case 1:
        c  =  "Olá,bem vindo ao mundo pokémon";
        break;
    case 2:
        c = "Você é garoto ou garota?";
        break;
    case 3:
        c = "aa";
        break;
    default:
        c = "c";
}

Note that no default was not added, since it will already exit switch anyway.

    
29.05.2016 / 02:31