官术网_书友最值得收藏!

Slider-related methods

The final section of the ControlBox class provides methods to increase or decrease the slider value. It is important to check two things when adjusting the slider value. First, we need to ensure the power is on. We can check that by making a call to our hasPower() method. The second check is to ensure we do not go outside the minimum-maximum range, as follows:

    // Method to increase slider value
public void sliderIncrease () {
if (hasPower()) {
if (getSliderValue() < SLIDER_MAX) {
sliderValue++;
System.out.println(sliderValue); // simulate sending value to digital display
}
}
}

// Method to decrease slider value
public void sliderDecrease () {
if (hasPower()) {
if (getSliderValue() > SLIDER_MIN) {
sliderValue--;
System.out.println(sliderValue); // simulate sending value to digital display
}
}
}

}

The slider value can be used to manage temperature, volume, quantity, or other values based on what system the control box is integrated with. This demonstrates the command pattern.

This section featured the source code that demonstrates the command design pattern.

主站蜘蛛池模板: 延寿县| 靖远县| 莫力| 南投市| 咸阳市| 靖江市| 六盘水市| 申扎县| 碌曲县| 垫江县| 新源县| 甘泉县| 永安市| 武鸣县| 贵溪市| 伊金霍洛旗| 怀集县| 上杭县| 岳阳县| 安康市| 澄迈县| 霞浦县| 西吉县| 莱阳市| 静宁县| 屯留县| 博野县| 梁山县| 密云县| 清远市| 凭祥市| 徐闻县| 霸州市| 大港区| 子洲县| 平阴县| 岳阳县| 炉霍县| 广州市| 五峰| 洮南市|