這是我第一次在一個程序中這樣做,我想知道是否有辦法將限制設置爲零。最大值是100,當用戶全部使用它時,最小值應該是0並且不應該小於0.這是我想出的代碼。感謝您的任何意見,幫助和想法。如何將數值限制設置爲零?
private class SliderListener implements ChangeListener {
@Override
public void stateChanged(ChangeEvent sl) {
int iSlider, dSlider, sSlider, wSlider;
iSlider = intSlider.getValue();
dSlider = dexSlider.getValue();
sSlider = strSlider.getValue();
wSlider = wisSlider.getValue();
//Store the points in the display field
points.setText(Double.toString(100 - (iSlider + dSlider
+ sSlider + wSlider)));
}
}
您是否指Double.toString(100 - (iSlider + dSlider + sSlider + wSlider))的最小值? – maheeka
'Math.max(0,otherNum)' – 4castle
是的。當我將前三個滑動到每個25時,第四個應該不會超過25. @maheeka – dullerthandull