April 2019
Intermediate to advanced
360 pages
9h 17m
English
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. ...
Read now
Unlock full access