I'm creating a simple game in Netbeans but I've come across a problem, when I've 500 coins and I try to add more, the total coins value will go to -1 therefore I think I need a else if statement in my code to stop and display a error message but I'm not sure how to write it?

Click Here

Click Here

As stultuske aleady said, cross-posting is generally considered poor nettiquete, as it leads to a duplication of effort, and anyone who sees the posts on both groups (and there usually are several who frequent both SO and Daniweb) will get tired of seeing the same posts repeated.

Also, as pointed out in the SO replies, posting an image of the code rather than the the code as editable text is also a problem; you don't want to make it difficult for the respondents to copy and re-write the code, as they usually will have to make changes to it to test it and for their reply to you. For something this size, it makes far more sense to paste into the post instead (though don't forget to use the Code button at the top when you do so. Much larger code sections, yes, you might want to have a link to the code instead, though you generally would be better off posting just the part of it that seems to be causing the problem in that case.

Edited 1 Year Ago by Schol-R-LEA

Is there a real need to have two separate totals? It seems to me that you could just use ocoins (preferably with a better variable name) and write:

    if (ocoins < MAXCOINS) {
        ocoins++;
        lblpoints.setText(String.ValueOf(MAXCOINS - ocoins);
    // ...

... where MAXCOINS is a class constant set at the beginning of the class:

static final int MAXCOINS = 500;

Note the use of the increment operator (++), also.

This article has been dead for over six months. Start a new discussion instead.