[Solved]Javafx Button Slider Handlers First Question S Url Https Wwwcheggcom Homework Help Questio Q37093601
JavaFX Button and Slider Handlers; first question’sURL:https://www.chegg.com/homework-help/questions-and-answers/javafx-w-button-slider-handlers-create-fill-described-methods-fireworkpanejava-file-rest-a-q37093192
I have already posted the other part of this assignmentso this is supposed to be in tandem with that. I will attempt tolink the two via a URL since I can’t relate posts. This one, theteacher provided us with most of the code.
FireworkControlPane represents one pane containing one “Start”button, one “Stop button, a Color Picker, and one “Speed” slider,and one “Beam Num” slider. In ControlPane, two objects ofFireworkControlPane are created, one to control a firework with redcolor initially, and another to control a firework with blue colorinitially. Thus your GUI should have four buttons (two Startbuttons and two Stop buttons), two color pickers, and four sliders(two Speed sliders and two Bean Num sliders). For eachFireworkControlPane, the start button, the stop button, and thecolor picker should be organized vertically, and on their righthand side, there should be a speed slider with a label “Speed” atits top. On the right side of the speed slider, there should be abeam num slider with a label “Beam Num” at its top. Underneath ofthese control objects, there should be two panes whose backgroundare black, and the one of the left should have a firework with redcolor and the one of the right should have a firework with bluecolor.
As soon as the GUI opensup, the beams (arcs) of each firework should start to expand fromits center towards the outside. Once the radius of the beams (arcs)reaches its limit (it will be explained later), then the radiusshould be re-set to 0, so that it will expand from its centeragain. When the stop button is pushed, the movement of itscorresponding firework should stop, and when the start button ispushed, the movement of its corresponding firework should re-start.Using the speed slider, its corresponding firework should expandtheir arcs quicker, or slower, and using the beam num slider, itscorresponding firework should increase its number of beams (arcs)or reduce it. In the picture below, the firework on the left has 4beams (arcs) and the one on the right has 28 beams (arcs).Note that these two sets of fireworks can have acompletely independent movement of each other and the size of theapplet here is approximately 550 X 400.

The FireworkControlPane is a subclass ofStackPane class. It contains 2 buttons including a start button anda stop button, and one color picker. It also two labels and twoSlider objects. It also contains one pane — an object ofFireworkPane class. Note that two objects of this class will beused, one for the red firework and one for the blue firework in theControlPane class.
The following constructor method is alreadygiven:
public FireworkControlPane(int width, int height, ColorinitialColor)
Its parameters are width and height of the pane, and the initialcolor of the fireworks for the pane. It should instantiate eachcomponents and arrange them using layout panes. The Slider forspeed should have its range from 0 to 50, and the initial delayshould be 20. Its major tick should be 10 and minor tick should be1, and it should be shown vertically. The Slider for the initialfirework beam number should have its range from 4 to 32, with theinitial value 8. Its major tick should be 4 and minor tick shouldbe 1, and it should be shown vertically. You can use other methodsdefined in Slider to make your Slider look like the one shown inthis page. An object of the ButtonHandler class should be set toeach button, an object of ColorHandler class should be set to thecolor picker an object of the SpeedHandler class should be added tothe speed Slider object, and an object of the BeamHandler classshould be added to the beam number Slider.
The below 2 classes can be defined as private classes ofthe FireworkControlPane. They implement the EventHandlerinterface.
ButtonHandler class
public void handle(ActionEvent event)
Its handle method should define an action for start and stopbottom. To distinguish buttons, you can use getSource() method ofthe ActionEvent object. For instance, if “start” is the startbutton for the fireworks pane, we can check if that button ispushed as:
ColorHandler class
public void handle(ActionEvent event)
Its handle method should get the color chosen by a user usingthe color picker, and set it to change the color of thefirework.
These 2 classes can be defined as private classes of theFireworkControlPane. They implement theChangeListener<Number> interface.
SpeedHandler class
public void changed(ObservableValue<? extends Number>observable, Number oldValue, Number newValue)
by getting the doubleValue of newValue parameter, and set it asthe new rate for the timeline of the corresponding firework.
BeamHandler class
public void changed(ObservableValue<? extends Number>observable, Number oldValue, Number newValue)
by getting the doubleValue of newValue parameter, and set it asthe new number of beams of the corresponding firework.
Code provided:
public class FireworkControlPane extends StackPane { //components of the Pane private FireworkPane fwPane; private Button start, stop; private Slider speed, beam; private Label label1, label2; private ColorPicker picker; private int width, height; private Color color; //Constructor to create all components, set their handler/listener, //and arrange them using layout panes. public FireworkControlPane(int width, int height, Color initialColor) { this.color = initialColor; this.width = width; this.height = height; //create a Pane displaying firework, with the specified color fwPane = new FireworkPane(initialColor, width); fwPane.setMinSize(width, height*(0.62)); fwPane.setMaxSize(width, height*(0.62)); //create 2 buttons, start and stop. start = new Button(“Start”); stop = new Button(“Stop”); //create a color picker with the specified initial color picker = new ColorPicker(color); start.setMaxSize(Double.MAX_VALUE,Double.MAX_VALUE); stop.setMaxSize(Double.MAX_VALUE,Double.MAX_VALUE); picker.setMaxSize(Double.MAX_VALUE,Double.MAX_VALUE); //organize two buttons and the color picker in vertical TilePane buttons1 = new TilePane(Orientation.VERTICAL); buttons1.setPrefColumns(1); buttons1.getChildren().addAll(start, stop, picker); //create a slider for the spead/rate with major tick 10, //minor tick 1. The minimum value is 0, the maximum //is 50, and the initial set value is 20. speed = new Slider(0, 50, 20); speed.setMajorTickUnit(10); speed.setMinorTickCount(1); speed.setShowTickLabels(true); speed.setShowTickMarks(true); speed.setOrientation(Orientation.VERTICAL); //create a label for the speed label1 = new Label(“Speed”); BorderPane Pane3 = new BorderPane(); Pane3.setTop(label1); Pane3.setCenter(speed); //create a slider for the number of beams/arcs for the firework with major tick spacing 4, //minor tick spacing 1. The minimum value is 4, the maximum //is 32, and the initial set value is 8. beam = new Slider(4, 32, 8); beam.setMajorTickUnit(4); beam.setMinorTickCount(1); beam.setShowTickLabels(true); beam.setShowTickMarks(true); beam.setOrientation(Orientation.VERTICAL); //create a label for the number of beams/arcs of the firework label2 = new Label(“Beam Num”); BorderPane Pane4 = new BorderPane(); Pane4.setTop(label2); Pane4.setCenter(beam); TilePane Pane6 = new TilePane(); Pane6.setPrefColumns(2); Pane6.getChildren().addAll(Pane3, Pane4); TilePane Pane5 = new TilePane(); Pane5.setPrefColumns(2); Pane5.getChildren().addAll(buttons1, Pane6); BorderPane Pane7 = new BorderPane(); Pane7.setTop(Pane5); Pane7.setCenter(fwPane); this.getChildren().add(Pane7); //Step #1: set an appropriate handler object to the buttons and the color picker /***to be completed***/ //Step #2: set an appropriate handler object to the sliders /***to be completed***/} //ButtonHandler defines actions to be performed when each button //is pushed. private class ButtonHandler implements EventHandler<ActionEvent> { public void handle(ActionEvent event) { Object action = event.getSource(); //Step #3 complete the method here /***to be completed***/ } } //end of ButtonHandler //ColorHandler defines actions to be performed when a color is chosen //using the color picker private class ColorHandler implements EventHandler<ActionEvent> { public void handle(ActionEvent event) { color = picker.getValue(); fwPane.changeColor(color); } } //end of ColorHandler //SpeedListener adjusts the speed/rate of firework based on //the chosen integer in the corresponding slider. private class SpeedHandler implements ChangeListener<Number> { public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { //Step #4 complete the method here /***to be completed***/ } } //end of SpeedListener //BeamListener adjusts the number of beams/arcs of firework based on //the chosen integer in the corresponding slider. private class BeamHandler implements ChangeListener<Number> { public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { //Step #5 complete the method here /***to be completed***/ } } //end of BeamListener }
Expert Answer
Answer to JavaFX Button and Slider Handlers; first question’s URL: https://www.chegg.com/homework-help/questions-and-answers/javaf… . . .
OR

