Appendix D
Answers to Self Tests

Chapter 1

1. What is the name of the open-source development environment you will use throughout this book?

NetBeans

2. True or false? You should download the version of NetBeans for All Developers.

False. You just need the version for JavaFX Developers.

3. True or false? The Java JDK will be installed for you automatically if needed (if you have the JRE installed).

True

4. Which NetBeans settings can you accept the default values for during installation?

The default NetBeans IDE path and the Java JDK installation path

5. What is the difference between the JavaFX SDK and the Java JDK?

The Java JDK is used to develop and compile in Java. The JavaFX SDK is based on the Java JDK and is used for JavaFX development.

6. What is the purpose of the NetBeans start page?

The purpose of the NetBeans start page is to offer you tips and news about developing in NetBeans and JavaFX.

7. True or false? You must successfully register NetBeans before using it.

False

8. At what website is NetBeans available?

www.netbeans.org

9. Name two other applications that closely resemble the functionality of JavaFX.

Adobe Flash and Microsoft Silverlight

10. JavaFX will compile for the Desktop, Web, and what other platforms?

Mobile and television

Chapter 2

1. What is the name of the frame where all your projects are listed?

Projects

2. What is the name of the wizard used to create a new JavaFX project?

The New JavaFX Project Wizard

3. What is another name for a namespace?

A package

4. Which panel of the NetBeans IDE lets you navigate through code samples?

The Palette

5. True or false? The Snippets panel contains predefine pieces of reusable code.

False. It is the Palette that contains predefine pieces of reusable code.

6. What file extension is assigned to JavaFX Script files?

.fx

7. What type of word is “package” in the JavaFX script?

A keyword, or reserved word

8. True or false? Every line of your script must end with a period.

False. Code lines must end with a semicolon.

9. What are the beginning and ending characters for comments?

    /* and */

10. What type of variable or attribute is the following?

   title: "MyApp"

A name-value pair

Chapter 3

1. What are the four basic attributes that need to be defined for a Text node?

font (size), x position, y position, and content

2. In what Palette menu is the Text node located?

Basic Shapes

3. What Run configuration is used to run your script as a Desktop application?

<default>

4. When creating a function, where would you specify input parameters?

Within the parentheses, following the function name

5. True or false? The function name MyFunction follows proper naming convention.

False. The name should be camel-cased and use descriptive action words.

6. What keyword is used to return a value from a function?

Return.

7. Name the two keywords that can be used to create variables.

var and def

8. How would you type a variable as string?

var <variable name> :String

9. True or false? The bind keyword is used to bind a variable and make sure it never changes.

False. Bind is used to bind a value to a variable.

10. What syntax would be used to bind a variable named tooMuchText to a content attribute?

content: bind tooMuchText

Chapter 4

1. What four attributes are needed to draw a line?

startX, startY, endX, and endY

2. How do you access the context menu?

CTRL-SPACE

3. What three delimiters can follow an attribute definition?

comma, semicolon, and nothing

4. What attribute controls the thickness of the line used to draw a shape?

strokeWidth

5. What package is needed to draw a polyline?

jaxafx.scene.shape.Polyline

6. What type of value is assigned to the points attribute of a Polyline element?

An array

7. True or false? The height attribute of the Rectangle element is the number of pixels from the start point to the top of the rectangle.

False. The height attribute is the number of pixels from the start point down.

8. What is the default value for the fill attribute of a Rectangle element?

Color.BLACK

9. True or false? RadiusX and radiusY comprise the point where the radius extends to.

False. RadiusX and radiusY are the radial lengths along the x and y axes, respectively.

10. What attribute configures the radius of a circle?

radius

Chapter 5

1. How many predefined colors are available in the Color class?

148

2. What are the three methods available in the Color class for mixing colors?

Color.rgb, Color.hsb, and Color.web

3. True or false? RGB stands for refraction, gradient, and blur.

False. RGB stands for red, green, and blue.

4. What is the acceptable value range for Hue?

0–360

5. In what package is the code for LinearGradients?

javafx.scene.paint.LinearGradient

6. What is the default value for the proportional parameter?

True

7. What is the acceptable value for startX when proportional is set to true?

0–1

8. True or false? The stops parameter tells the gradient what point to stop on.

False. The stops parameter is an array of colors and the corresponding indications of where they are in the gradient.

9. True or false? Gradients can be composed of more than two colors.

True

10. Which gradient is best for curvilinear shapes?

RadialGradients

Chapter 6

1. What node is used to display images?

ImageView

2. What class is used to write an image to the ImageView node?

Image()

3. True or false? An Image class can accept images from the Web.

True

4. What value does the {__DIR__} constant contain?

The path to the package location

5. True or false? To have an image load in the background, use the BackgroundImage loader.

False. Set the backgroundLoading attribute to true.

6. What is the name of the tool used to export images from Adobe Photoshop and Adobe Illustrator for JavaFX?

JavaFX Production Suite

7. True or false? You must add jfx: to the beginning of each layer name to access those layers by name in your script.

True

8. What node is used to load images from an FXZ file?

FXDNode

9. True or false? The FXZ file is a compressed file that contains images and definitions.

True

10. What method is used to load an image layer?

getNode()

Chapter 7

1. How do you assign a type to a var?

Use the : <type> notation. For example, use : ImageView to type a var as an ImageView.

2. What effect adjusts only the higher contrast areas of your node to make them glow?

Bloom

3. True or false? All the parameters of ColorAdjust default to 0 if they are not specified.

False. Contrast defaults to 1.

4. What parameter needs to be specified to create a GaussianBlur effect?

radius

5. What is the difference between Glow and Bloom?

Glow is applied to the entire image, whereas Bloom only applies to the areas of higher contrast.

6. True or false? You do not need to specify both a radius and a height/width for a DropShadow.

True

7. Which effect takes all the opaque areas of your image and makes them transparent?

InvertMask

8. What are the three different lights that can be used in the Lighting Effect?

DistantLight, PointLight, and SpotLight

9. What does the following code do?

   butterfly.rotate = 45;

It rotates the butterfly image 45 degrees.

10. How many parameters need to be set to create a Perspective Transform effect?

Eight

Chapter 8

1. Why is timing important to animation?

Timing is critical to producing smooth animation.

2. What controls the timer in JavaFX animation?

A Timeline

3. What does a Timeline take in as a parameter?

keyFrame

4. How do you start the Timeline?

.play()

5. True or false? The transition notation tells the Timeline to build all the values between the ones specified in your keyframes.

False. It is the keyword tween that does this.

6. Which parameter sets the number of times a Timeline executes?

repeatCount

7. What is the purpose of ClosePath()?

To “connect the dots” and close your path (that is, if it does not close organically)

8. A path is created from a group of what?

Elements

9. What function is used to create an AnimationPath from a Path node?

createFromPath()

10. Which Orientation Type will change the orientation of the node as it moves along the path?

ORTHOGONAL_TO_TANGENT

Chapter 9

1. Where are the onMouse* events inherited from?

Node

2. When is onMouseEntered fired?

When the mouse pointer enters the Node to which the event is attached

3. True or false? The onMouseReleased event only fires when the mouse is dragged.

True. onMouseReleased is only fired when onMousePressed is followed by onMouseDragged.

4. True or false? Anything that inherits from Node can trap onMouse* events.

True

5. When events are used, what is the purpose of an anonymous function?

The purpose of an anonymous function is to immediately perform an action when the event is fired.

6. Which mouse event is fired when the mouse pointer exits the node to which the event is attached?

onMouseExited

7. What three events are fired when the user interacts with the keyboard?

onKeyPressed, onKeyReleased, and onKeyTyped

8. In what order are the key events fired?

onKeyPressed, onKeyTyped, and then onKeyReleased

9. What property will allow a node to accept focus?

focusTraversable

10. True or false? The navigational buttons on a mobile phone will fire the onKeyTyped event.

False

Chapter 10

1. What package contains the swing components for JavaFX?

javafx.ext.swing

2. True or false? The swing JavaFX package contains all the components available in Java.

False. The JavaFX swing package only contains a subset of what is available in Java.

3. Are the onMouse* and onKey* events available to swing components?

Yes, swing components for JavaFX inherit from Node.

4. What are the JavaFX string interpolator operators?

{ and }

5. What property of the SwingButton can hold an anonymous function that will execute when the button is clicked?

action

6. What property of the SwingButton can be used to change the shape of the button?

clip

7. True or false? The isChecked property of the SwingCheckBox will tell you if the box is checked.

False. The selected property will tell you if the box is checked.

8. What swing component is used to populate SwingComboBox?

SwingComboBoxItem

9. How do you set a SwingComboBoxItem to the default choice?

Set its selected property to true.

10. What property of SwingComboBox will tell you what SwingComboBoxItem has been selected?

selectedItem

Chapter 11

1. What process lets you take methods and properties from one class and change their default actions and behaviors?

Overriding

2. When you’re creating a class, what keyword forces your class to inherit the methods and properties of another?

extends

3. In the following example, what will a call to YourDog.displayBreed print?

   public class MyDog extends Dog{
   override function displayBreed(){
   println("Elkhound");
   }
   }
   public class YourDog extends Dog{
   }

Elkhound

4. True or false? Ensuring that your files are all in the same package will make referencing them easier.

True

5. True or false? After inheriting from a class, only attributes that you override are available to you in another class.

False. All methods and attributes are available to you.

6. What trigger will execute when an attribute changes?

on replace

7. What statement will take an expression for a true or false result and then execute code accordingly?

if...else

8. True or false? You have to call a custom-created node from a script to use it.

True

9. What node do you inherit from to create a custom node?

CustomNode

10. What method of CustomNode do you override to return your node to the calling script?

create()

Chapter 12

1. What node is used to hold a MediaPlayer?

MediaView

2. What package contains all the nodes needed to work with media files?

javafx.scene.media

3. What property of the MediaPlayer tells the media file to play once it has loaded?

autoPlay

4. What media formats can the MediaPlayer play?

Any format supported by QuickTime or Windows Media Player

5. What property of the MediaPlayer will pause media playback?

pause()

6. True or false? MediaPlayer.mediaLength() will give you the total running time of a media file.

False. MediaPlayer.media.duration.toMillis() will give you the running time in milliseconds.

7. What type is MediaPlayer.currentTime?

Duration

8. What type of binding allows for bidirectional updating?

binding with inverse

9. True or false? Using inverse binding, you can bind directly to a value.

False. You must bind indirectly through a variable.

10. What property of MediaPlayer can you bind to in controlling the playback volume?

volume

Chapter 13

1. What layout organizes your nodes horizontally across a Scene?

HBox

2. True or false? The HBox is located in the javafx.scene.HBox package.

False. The HBox is located in the javafx.scene.layout package.

3. What property holds the nodes for a layout to organize?

content

4. True or false? You must be sure to set the x and y coordinates of each node you place in a layout.

False. The layout takes care of the x and y coordinates for you.

5. Can effects be applied to layouts?

Yes. Because layouts inherit from Node, they can use effects.

6. What layout organizes nodes vertically down a Scene?

VBox

7. What is the name given to layouts that are combined to produce a new layout?

Nested layouts

8. True or false? Fore layouts to be nested, one must inherit from the other.

False. One layout simply needs to be added to the other’s content.

9. True or false? Only two layouts can be nested.

False. Multiple layouts can be nested.

10. Name four layouts other than the VBox and HBox.

ClipView, Flow, Stack, and Tile

Chapter 14

1. What is Cascading Style Sheets (CSS)?

CSS is a styling language that allows you to separate the styling elements of an object from the object itself.

2. What file extension is used for Cascading Style Sheets?

.css

3. What wizard helps you create and add a CSS to your package?

The New File Wizard

4. If you use the wizard to create your CSS, what class is added by default?

root

5. True or false? To create a CSS class that applies to all nodes of a certain type, the name of the class should be the name of the node type in lowercase.

True

6. What prefix is added to every Node property to call it from a CSS class?

-fx-

7. What property of Scene will let you apply a style sheet to your script?

styleSheets

8. True or false? You can only add one style sheet to a Scene.

False. You can add multiple style sheets to any particular Scene.

9. What Node property allows you to assign a specific CSS class to a node?

styleClass

10. True or false? If you have a node with a node-applied CSS class and a styleClass property, the style in the styleClass will override that in the node-applied style.

True

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.131.255