From the course: Learning JavaFX GUI Development

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Draw lines and shapes

Draw lines and shapes

From the course: Learning JavaFX GUI Development

Start my 1-month free trial

Draw lines and shapes

- [Voiceover] The JavaFX API provides a set of two D-class objects that can be used to draw lines and shapes, similar to the way we can draw in Swing. Here is a sample scene that I created by adding lines and shapes using the fill and stroke properties to add color. As you can see, it's a very simple scene with a sky-blue background, two shapes, a circle and a rectangle, a line for my seesaw that has a very thick stroke, and then two legs. Here is a quick tip on creating scenes in Java Effects or any GUI application for that matter. When I want to draw a scene in Java, I usually get some graph paper and sketch it out first. This helps to easily identify the correct XY coordinates and other variables for the size of your shapes. Remember, the XY coordinate system in a Java window starts at 00 in the upper left hand corner and the values of X and Y increase as X goes across horizontally and Y goes down vertically. Here is the sketch that I used to create the playground. I placed my…

Contents