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

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.

主站蜘蛛池模板: 石河子市| 盱眙县| 浑源县| 南溪县| 恩施市| 绍兴县| 泾阳县| 遂溪县| 黄浦区| 策勒县| 攀枝花市| 赣榆县| 博湖县| 高州市| 金塔县| 松江区| 汕头市| 昌平区| 微山县| 宣汉县| 阿荣旗| 南涧| 宜都市| 镇坪县| 霍邱县| 博白县| 刚察县| 沧源| 盖州市| 临海市| 长兴县| 武平县| 开封县| 炎陵县| 武城县| 惠州市| 额尔古纳市| 沈丘县| 星子县| 穆棱市| 读书|