Starting from:

$30

CS221 Assignment 5 Solved


How to submit: compress and upload source files to Blackboard
JavaFX. Assignment 5  

In this assignment we utilize Java’s FX technology and object serialization to add functionalities to an existing application. Chapters 12, 13, and 15 are particularly helpful.

Note:  

ü  This is an individual assignment; please do your own work, sharing and/or copying code and/or solution ideas with/from others will result in a grade of 0 and disciplinary actions for all involved parties. If you run into problems and have done your best to solve them, please contact me before/after class or by e-mail. 

ü  A 20% grade deduction for every day the assignment is late. Preamble 

Before      you      begin      working      on      this      assignment,      download      the      three      accompanying       files 

(𝑀𝑎𝑖𝑛. 𝑗𝑎𝑣𝑎, 𝐶𝑜𝑛𝑡𝑟𝑜𝑙𝑙𝑒𝑟_𝐴𝑠𝑠𝑖𝑔𝑛𝑚𝑒𝑛𝑡5. 𝑗𝑎𝑣𝑎, and 𝐴𝑠𝑠𝑖𝑔𝑛𝑚𝑒𝑛𝑡5. 𝑓𝑥𝑚𝑙). Crate a new 𝐽𝑎𝑣𝑎𝐹𝑥 project using the defaults shown during class. Remember to set the language to 𝐹𝑋𝑀𝐿; the project’s name maybe set to anything you would like. If you use a different IDE, please adjust your project’s parameters accordingly. The package name is assumed be 𝑎𝑝𝑝𝑙𝑖𝑐𝑎𝑡𝑖𝑜𝑛, the controller’s name is 𝐶𝑜𝑛𝑡𝑟𝑜𝑙𝑙𝑒𝑟_𝐴𝑠𝑠𝑖𝑔𝑛𝑚𝑒𝑛𝑡5, and the driver class is 𝑀𝑎𝑖𝑛.  

Once the project is created, copy the provided files and overwrite the ones generated by your IDE. Next launch the application, it should look like the one in Figure 1. Do not proceed beyond this point unless you complete this step and you fully test the initial application’s functionalities.

What to submit? 

1.     𝐴𝑠𝑠𝑖𝑔𝑛𝑚𝑒𝑛𝑡5. 𝑓𝑥𝑚𝑙 

2.     𝐶𝑜𝑛𝑡𝑟𝑜𝑙𝑙𝑒𝑟_𝐴𝑠𝑠𝑖𝑔𝑛𝑚𝑒𝑛𝑡5. 𝑗𝑎𝑣𝑎 

3.     𝑀𝑎𝑖𝑛. 𝑗𝑎𝑣𝑎 

4.     Any new classes added for XML serialization 

Next, add the following features, the finished application must look like the one in Figure 2:

I. (30pts) GUI Controls 

1.     Set the title of the window such that it displays your name. 

2.     Change the font color for each of the drawing colors to reflect its name 

3.     Add a new 𝑏𝑟𝑜𝑤𝑛 drawing color 

4.     Add a new pen size for 𝑋       𝐿𝑎𝑟𝑔𝑒 circles 

5.     Add a new button with label “𝑆𝑒𝑟𝑖𝑎𝑙𝑖𝑧𝑒 𝑡𝑜 𝑋𝑀𝐿” 

6.     Add the labels and slider above the drawing panel as shown in Figure 2.  

Hint:  

ü  wrap the drawing panel in a 𝐵𝑜𝑟𝑑𝑒𝑟𝑃𝑎𝑛𝑒 before adding the control in order for the panel to resize with the window.  

ü  Set the slider properties: C Min value: 0 

C  Max Value: 255 

C  Major Ticks: 25 

C  Minor Ticks: 3 

II. (70pts) Events  

1.     (5pts) Draw circles using brown color 

2.     (5pts) Draw circles using X-Large pen 

3.     (30pts) Serialize to XML. When this button is clicked, show a file open dialog box which allows for the selection of an XML file. Use JavaFX 𝐹𝑖𝑙𝑒𝐶ℎ𝑜𝑜𝑠𝑒𝑟 class detailed in Chapter 15 slides 72-88. Next, serialize all drawn circles into the selected XML file. One way to achieve this process is as follows: 

i.        Create a POJO class (e.g. 𝐴5𝑆ℎ𝑎𝑝𝑒) with three members for 𝑥 𝑐𝑜𝑜𝑟𝑑𝑖𝑛𝑎𝑡𝑒𝑠, y coordinates, and 𝑟𝑎𝑑𝑖𝑢𝑠. This is similar to the class on slide 52 in Chapter 15. Note that we are skipping the circle’s color. 

ii.      Create a container class to hold objects of type 𝐴5𝑆ℎ𝑎𝑝𝑒 in an 𝐴𝑟𝑟𝑎𝑦𝐿𝑖𝑠𝑡 name the class 𝐿𝑖𝑠𝑡𝐴5𝑆ℎ𝑎𝑝𝑒. See slide 59 of Chapter 15 for an example. 

iii.     For every drawn circle on the panel, create an object of type 𝐴5𝑆ℎ𝑎𝑝𝑒 and add it to the 𝐴𝑟𝑟𝑎𝑦𝐿𝑖𝑠𝑡 in 

𝐿𝑖𝑠𝑡𝐴5𝑆ℎ𝑎𝑝𝑒.  iv. Using JAXB, serialize the objects to the XML file. See Slides 60 – 62 of Chapter 15. 

4.     (30) Background Slider. When the slider is dragged to the right the drawing panel’s background gets a higher blue construction. See Figures 3‐5.

Hint:

ü  The background color can be set using the style property. The following example changes the background to GREEN by specifying the RGB color value in hexadecimal format:

 

𝑝𝑎𝑛𝑒𝑙𝐷𝑟𝑎𝑤. 𝑠𝑒𝑡𝑆𝑡𝑦𝑙𝑒 "-fx-background-color: #0000FF" ß Sets the background of 𝑝𝑎𝑛𝑒𝑙𝐷𝑟𝑎𝑤 to blue

 𝑝𝑎𝑛𝑒𝑙𝐷𝑟𝑎𝑤. 𝑠𝑒𝑡𝑆𝑡𝑦𝑙𝑒 "-fx-background-color: #FFFFFF"  ß Sets the background of 𝑝𝑎𝑛𝑒𝑙𝐷𝑟𝑎𝑤 to white. This happens when the slider’s value is 0.

 

ü  Integer values maybe converted to hex using 𝐼𝑛𝑡𝑒𝑔𝑒𝑟. 𝑡𝑜𝐻𝑒𝑥𝑆𝑡𝑟𝑖𝑛𝑔

ü  The slider’s change event maybe set as shown in slide 94 in Chapter 12. Figures: 

  

                            Figure 1: Initial Window                                                                                         Figure 2: Final Window 

  

         Figure 3: Blue slider about a 1/3 of the way into blue                                Figure 4: Blue slider about 2/3 of the way into blue 

                   

 

 

More products