Thompson Rivers University
Adding the Square
Assignment 5 User Interfaces FX - SM 2025Now that we’ve got our color options using radio buttons on the left, it’s time to add the square that appears on the right. This is the visual part that actually responds to user input.
The square is going to be a Rectangle object from the JavaFX library. And remember, we want to:
Set its initial color to red (to match the default radio button)
Start it at 75% of the max size
Place it in the window beside the radio buttons
Create the Rectangle
The assignment says the square should be 75% of a “maximum” size when the app starts. We’ll first define a constant for that maximum value. Put this at the top of your class:
private static final double MAX_SQUARE_SIZE = 200.0;This means our full square size is 200 pixels. To get 75%, we just multiply:
Keep reading this lesson
You've reached the end of the free preview. Unlock the rest of this lesson plus 54 more lessons in Thompson Rivers University.
- Unlimited coding questions
- Unlimited access to all classroom material
- Weekly live call for questions and guidance
- 3,000 AI tutor tokens / month
- Personal SQL database (3 MB)
- Progress tracking
Cancel any time.