“Enlarge” and “Shrink”
Add two new buttons that will be used to enlarge or shrink the circle, placing these buttons below the others. The text on these buttons can be simply “Enlarge” and “Shrink”. The size of a circle object is determined by the radius property, and the Circle class provides two methods to access and change its radius. Assuming c refers to a circle object, c.getRadius() returns the current radius of the circle; c.setRadius(r) changes the radius of the circle to the value r. You will need to add event handlers for the Enlarge and Shrink buttons, which should increase or decrease the radius of the circle by 10 pixels each time that the button is clicked. Remember that the handler for each button must be activated by invoking the setOnAction method, as we did for the other buttons. The code to handle these events will need to be added by creating two new branches inside the handle method of your program. • For the Shrink button, add a condition to the handler, to prevent the circle from becoming invisible, so it will not change the radius if it would shrink to zero or a negative number. • For the Enlarge button, add a condition to the handler, to prevent the circle from becoming larger than the window. The scene is is created with a width of 450 pixels and the buttons may have a width of up to 80 pixels, so do not increase the radius if it would become larger than 185 pixels. It is alright for part of the circle to extend outside the visible window, but don’t let the circle fill the entire window.
Step by step
Solved in 5 steps with 4 images