Java – disable the int spinner plus button

The following code is very useful when the user allocates the total number of statistical points I allocate However, I want to disable only the plus button so that they can reduce the statistics and add them again

if ((strengthModel.getNumber().intValue()) + (constitutionModel.getNumber().intValue()) + (dexterityModel.getNumber().intValue()) + (intelligenceModel.getNumber().intValue()) > 49){
     strengthSpinner.setEnabled(false);
     constitutionSpinner.setEnabled(false);
     dexteritySpinner.setEnabled(false);
     intelligenceSpinner.setEnabled(false);
}

Is the int rotator possible? I didn't see it in the document

Edit more information: you can propagate your statistics points or assign them all to a statistics The maximum value of each model is 10 unused points

Solution

For those who find this topic here, how do I solve my problem:

public void stateChanged(ChangeEvent e) {
    Component[] components = characterCreationPanel.getComponents();
    Component component = null; 
    strengthValue = strengthModel.getNumber().intValue();
    constitutionValue = constitutionModel.getNumber().intValue();
    dexterityValue = dexterityModel.getNumber().intValue();
    intelligenceValue = intelligenceModel.getNumber().intValue();
    for (int i = 0; i < components.length; i++)
    {
        component = components[i];
        if (component instanceof JLabel){
            if (((JLabel) component).getText().substring(0,5).equals("Stat ")){
                ((JLabel) component).setText("Stat Points Left: " + Integer.toString(50 - (strengthValue + constitutionValue + dexterityValue + intelligenceValue)));
                if ((strengthValue + constitutionValue + dexterityValue + intelligenceValue) == 50){
                    System.out.println("Hit your cap.");
                }
            }       
        }
        strengthModel.setMaximum(50 - (constitutionValue + dexterityValue + intelligenceValue));
        constitutionModel.setMaximum(50 - (strengthValue + dexterityValue + intelligenceValue));
        dexterityModel.setMaximum(50 - (strengthValue + constitutionValue + intelligenceValue));
        intelligenceModel.setMaximum(50 - (strengthValue + constitutionValue + dexterityValue));
    }
}

Thank "ziesemer" for getting the hint of setmaximum

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>