Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 10 ■ User InterfaCe DesIgn InteraCtIvIty: event hanDlIng anD ImagIng effeCts


Next, we will replace the bootstrap code inside this createSpecialEffects() method with special
effects code.


Drop Shadows: Adding Drop Shadows to Your TextFlow Object


Now it is time to add Java code into the empty createSpecialEffects() method to set up the drop shadowing
effect. You will apply this to your TextFlow objects later by using the .setEffect() method call. The first thing
that you will need to do is to declare a DropShadow object named dropShadow at the top of your class and
use an Alt+Enter work process to have NetBeans generate an import statement for you. Next, inside the
createSpecialEffects() method, instantiate this object using the Java new keyword and the DropShadow()
constructor method. Next, use the .setRadius() method call off of the dropShadow object to set a shadow
radius (how much it spreads out from the source) of 4.0 pixels. Next, use the .setOffsetX() and .setOffsetY()
method calls with a setting of 3.0 pixels to offset the shadow diagonally to the right (use negative values to go
the other direction). Finally, use a .setColor() method call to specify a DARKGRAY Color class constant. The
code, shown highlighted in Figure 10-10, should look like the following:


DropShadow dropShadow;
...
private void createSpecialEffects() {
dropShadow = new DropShadow();
dropShadow.setRadius(4.0);
dropShadow.setOffsetX(3.0);
dropShadow.setOffsetY(3.0);
dropShadow.setColor(Color.DARKGRAY);
}


Figure 10-9. Add a createSpecialEffects() method call at the top of .start() so that NetBeans creates the
method body

Free download pdf