HW4 Draw the Chinese Flag In JavaFX (With Solution)

Due: Friday, March 13, 2019  11:59pm

SOLUTION

Chapter 14 Homework

Write a program that draws and displays a Chinese flag. Note this is not displayed from one big image, rather it is drawn using shapes and an image of a  Chinese Star.

Specifications:

  • A good size flag should be 600px wide by 400px high.
  • There’s no point allowing the user to resize the window so make sure you set the the primary stage resizable property to false.
  • Do not just show an image of the Chinese flag!
  • 10 out 0f 10, if you manually layout stars.
  • 12 out of 10, if you use a loop to layout the 4 small stars.
  • Maximum points given if you use multiple classes and/or methods.  Do not put all code in the start method.

FYI: Dimensions and proportions of the US Flag: https://en.wikipedia.org/wiki/Flag_of_China

Extra Credit for a total of 15 out of 10 points.

Add scalability to your application.  Adjusting the window size should adjust the flag accordingly.  If you do this, set the resizable property to true.  Use property binding based on the window’s width and height to the components of the pane.  Property Binding would need to be set on all the nodes in your pane.  As perhaps a better technique would be to use the code shown for the polygon example in Chapter 14.

Here is an example of Red Stripe Scalability.

Here is an example of Red Stripe Scalability Using No Property Binding

Oh, for 20 out of 10 points . . .

If you do the resizable flag, what will happen is the flag distorts when you resize the stage!  We can’t have that.

Investigate what needs to be done to keep the flag always proportional as you resize the stage.