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

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.

主站蜘蛛池模板: 资阳市| 康定县| 宁晋县| 金溪县| 华容县| 礼泉县| 灵川县| 海城市| 武川县| 白沙| 保山市| 会东县| 彭泽县| 包头市| 济源市| 安平县| 万载县| 商南县| 香河县| 永嘉县| 宁明县| 阿拉尔市| 肇庆市| 武安市| 集安市| 南城县| 郧西县| 韶关市| 上蔡县| 买车| 启东市| 白朗县| 同仁县| 通州区| 徐州市| 枣庄市| 老河口市| 炉霍县| 肇庆市| 怀远县| 新乡县|