Menu

[Solved]Javafx W Button Slider Handlers Portion Assignment S Url Https Wwwcheggcom Homework Help Q Q37093192

JavaFX w/ Button and Slider Handlers; Other portion ofassignment’s URL:https://www.chegg.com/homework-help/questions-and-answers/javafx-button-slider-handlers-first-question-s-url-https-wwwcheggcom-homework-help-questio-q37093601

I have to create and fill out the described methodsbelow in a FireworkPane.java file. I will have the rest of theassignment posted in another question since it is too long for onepost. This should be fine on its own though. I was provided twoother .java files but they’re setting up the Panes and such so ifyou need those, I can provide the code.

FireworkPane class a subclass of Pane class. It is used todefine a pane where fireworks are moving. It has the followingattributes:

Attribute nameAttribute typeDescriptioncenterXdoublex-coordinate of the center of the firework.centerYdoubley-coordinate of the center of the firework.radiusdoubleradius of the firework.radiusLimitdoublethe largest radius that the firework can have.angleSizedoublethe arc angle of each arc/beam of the fireworktimeline1TimelineAn object of Timeline in javafx.animation package. This is usedto control the movement of the firework.stepdoubleeach step that the radius can increase for each timelinetickbeamNumintthe number of beams/arcs of the firework.colorColorcolor of the firework.

The following constructor method should be provided:

public FireworkPane(Color color, int width)

The color is initialized to the value of the color parameter.centerX and centerY should be initialized to width/2. radiusLimitshould be initialized to (width-10)/(4.0); The initial radius valueshould be 25.0; The initial beamNum should be 8. The initialangleSize should be 360/(beamNum*2), and its step should be 2.0.The background of the FireworkPane should be set to black.
Then it should create arcs and add them to the FireworkPane asfollows:

for (int currentAngle=0; currentAngle <= 360; currentAngle += 2*angleSize) { Arc arc1 = new Arc(centerX, centerY, radius, radius, currentAngle, angleSize); arc1.setFill(color); arc1.setStroke(color); arc1.setType(ArcType.ROUND); this.getChildren().add(arc1); }

Then timeline1 should be instantiated using an object ofKeyFrame with Duration time being 500 mill sec, with an object ofFireworkHandler class (FireworkHandler class will be definedlater).
Its cycle count should be indefinite, and its initial rate shouldbe 20, and it should start ticking as soon as the pane is openedusing the following code:

timeline1.setCycleCount(Timeline.INDEFINITE); timeline1.setRate(20); //default rate = 20 timeline1.play();

public void resume()

The timeline1 should start again using its play method.

public void suspend()

The timeline1 should pause again using its pause method.

public void changeColor(Color anotherColor)

The changeColor method sets the value of the color variable ofthe firework using the parameter value.

public void setBeamNumber(int beam)

It sets the value of the beamNum variable of the firework usingthe parameter value, and also sets the value of angleSize to be(360.0)/(beamNum*2)

public void setRate(int rate1)

This method sets the rate of the timeline1 object.

FireworkHandler class

This class can be defined as a private class of theFireworkPane. It implements EventHandler interface.

public void handle(ActionEvent event)

This method is executed for every time interval specified by theTimeline object.
Its handle method defines how a firework is drawn by changing itsradius by adding “step” value to it, and re-draw arcs using thecurrent values of beanNum, angleSize, centerX, centerY, color,etc.
First, you need to clear all arcs in the pane as:
getChildren().clear();
since the number of arcs might have been changed based on thenumber of beamNum.
Then you can add a new set of arcs as:

angleSize = 360/(beamNum*2); for (int currentAngle=0; currentAngle <= 360; currentAngle += 2*angleSize) { Arc arc1 = new Arc(centerX, centerY, radius, radius, currentAngle, angleSize); arc1.setFill(color); arc1.setStroke(color); arc1.setType(ArcType.ROUND); getChildren().add(arc1); }Also if the value of radius becomes same or larger than radiusLimit, then the radius needs to be re-set to 0.

Expert Answer


Answer to JavaFX w/ Button and Slider Handlers; Other portion of assignment’s URL: https://www.chegg.com/homework-help/questions-a… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *