How to put an integer into a label

1

I'm trying to put a sort of punctuation counter on an ex Jlabel: you hit an issue the score goes to 1, you miss and nothing happens with the punctuation.

I tried to do it this way:

   private void confirmarActionPerformed(java.awt.event.ActionEvent evt) {                                          
    while (true){
    String pont = " ";
    int pontuacao = Integer.parseInt(pont);
    if (confirmar == a){
        a.setBackground(Color.green);

    }else{
         a.setBackground(Color.red);
    }

   }

}

Error:

  Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""

    
asked by anonymous 06.07.2017 / 15:01

1 answer

1

You are giving an error because you are declaring pont as String and you are trying to convert " " to Int and of course it will give conversion error. It is impossible to convert nothing to integer , integer must always have some numeric value.

    
06.07.2017 / 15:04