Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java N-Sided Regular Polygon

xcjamesxc
xcjamesxc 


s. Write a program that displays a regular polygon and uses two buttons named +1 and -1 to increase or decrease the size of the polygon, as shown in the following figure. To receive full credit your program will need to meet the following specifications: 1.Create the UI that looks like the example dialogs. 2.Your program should correctly display an n-sided polygon. 3.Your program should handle action events from the buttons. 4.Your program should redisplay the polygon when the user clicks the buttons. Example Dialogs: What you will need in for the code: Your java code will have three sections: 1.The YourNameAssignment1 class which will be an extension of the Application class a.The start method will be located here b.The pane’s width and height will be set to 270 x 210 c. An instance of the polygon class (see item 3 below) is created with a default of 6 sides d.The polygon instance is set in the center of the BorderPane e.The bindings to the polygon class’s methods to increase and decrease the number of sides will be located here f. The BorderPane, HBox and Scene will be instantiated here g.The state’s title is set h.The + and – buttons are created and located in the HBox 2.a main method for the start of program execution a.The launch method will be called here 3.a class that models the polygon which will be an extension of the StackPane class a.The polygon will be instantiated here i.The constructor: 1.is where the default number of sides will set (6) 2.the polygon instance will be added to the pane 3.the fill color will be set 4.the stroke color will be set 5.the paint method is initially called b.The paint method will be defined here i.An ObservableList of type Double will be created ii.The width and height of the polygon will be set to 200 x 200 iii.The radius will be calculated iv.Points in the polygon will be added to the list using the following formulas for the x and y locations of the point: for (int i = 0; i < numberOfSides; i++) { list.add(centerX + radius * Math.cos(2 * i * Math.PI / numberOfSides)); list.add(centerY - radius * Math.sin(2 * i * Math.PI / numberOfSides)); } c. The methods to increase and decrease the number of sides of the polygon are defined here Submission: Submit this entire project subdirectory asYourNameAssignment2.java, in the Assignment 2 Section on or before the due date. Attachments Tags
Clarifications

Answers