Final Exam JavaFX PDF
Document Details
Uploaded by Deleted User
Tags
Summary
This document contains questions about JavaFX programming, including topics such as defining JavaFX main classes, stages, panes, nodes, bindings, colors, and fonts. The questions are likely from an exam, possibly related to a computer science or software engineering course.
Full Transcript
14.3.1 **How do you define a JavaFX main class?** -You define a JavaFX main class by extending the Application class. **What is the signature of the start method?** -public void start(Stage primaryStage) **What is a stage?** -A stage is a window that holds the scene. **What is a primary stage...
14.3.1 **How do you define a JavaFX main class?** -You define a JavaFX main class by extending the Application class. **What is the signature of the start method?** -public void start(Stage primaryStage) **What is a stage?** -A stage is a window that holds the scene. **What is a primary stage?** -Main window **Is a primary stage automatically created?** -Yes **How do you display a stage?** -stage.show(); **Can you prevent the user from resizing the stage?** -stage.setResizable(false); **Can you replace Application.launch(args) by launch(args) in line 22 in Listing 14.1?** 14.4.2 **What is a pane?** -A pane is used to hold and organize nodes **What is a node?** -A node is a visual component that can be displayed **How do you place a node in a pane?** -pane.getChildren().add(node); **Can you directly place a Shape or an ImageView into a Scene?** -No **Can you directly place a Control or a Pane into a Scene?** -Yes using new Scene(Parent), parent being the superclass for control and pane 14.4.3 **How do you create a Circle?** Circle circle = new Circle(); **How do you set its center location and radius?** circle.setCenterX, circle.setCenterY, and circle.setRadius() **How do you set its stroke color and fill color?** circle.setStroke(color), circle.setFill(color) 14.5.1 **What is a binding property?** -Property that binds with a source object **What interface defines a binding property?** if it's an instance of Property **What interface defines a source object?** if it's an instance of ObservableValue **What are the binding object types for int, long, float, double, and boolean?** -IntegerProperty, LongProperty, DoubleProperty, and BooleanProperty **Are Integer and Double binding properties?** No **Can Integer and Double be used as source objects in a binding?** No 14.5.2 **For a binding property named age of the IntegerProperty type, what is its value getter method, value setter method, and property getter method?** -getter method: public int getAge() -settler method: public void setAge(int age) -property getter method: public IntegerProperty ageProperty() 14.5.3 **Can you create an object of IntegerProperty using new IntegerProperty(3)? If not, what is the correct way to create it?** -No. IntegerProperty is an abstract class. You have to use new SimpleIntegerProperty(4) to create an instance of IntegerProperty. -14.5.4 **What is a unidirectional binding and what is bidirectional binding?** -A unidirectional binding binds a target with a source. A bidirectional binding binds two objects together. **Are all binding properties capable of bidirectional binding?** -Not all binding properties can be bidirectional. **Write a statement to bind property d1 with property d2 bidirectionally.** -d1.bindBidirectional(d2) 14.6.1 **How do you set a style of a node with border color red? Modify the code to set the text color for the button to red.** -node.setStyle(\"-fx-border: red\"); -text.setStyle(\"-fx-fill: red\"); 14.6.2 **Can you rotate a pane, a text, or a button? Modify the code to rotate the button 15 degrees counterclockwise?** -Yes. button.setRotate(-15); **How do you test if a point is inside a node?** -node.contains(x, y); **How do you scale up or down a node?** -node.setScaleX(2.0); -node.setScaleX(0.2); 14.7.1 **How do you create a color?** -You can use the Color constructor or static methods in the Color class to create Color objects. **What is wrong about creating a Color using new Color(1.2, 2.3, 3.5, 4)?** -new Color(1.2, 2.3, 3.5, 4) is wrong because the parameter values must be between 0 and 1. **Which of two colors is darker, new Color(0, 0, 0, 1) or new Color(1, 1, 1, 1)?** new Color(0, 0, 0, 1) is darker than new Color(1, 1, 1, 1). **Does invoking c.darker() change the color value in c?** -Invoking c.darker() returns a new Color. Color is immutable. 14.7.2 **How do you create a Color object with a random color?** -new Color(Math.random(), Math.random(), Math.random(), 1) 14.7.3 **How do you set a circle object c with blue fill color using the setFill method and using the setStyle method?** -c.setFill(Color.BLUE) -c.setStyle(\"-fx-fill: blue\") 14.8.1 **How do you create a Font object with font name Courier, size 20, and weight bold?** -new Font(\"Courier\", Weight.BOLD, 20) 14.8.2 **How do you find all available fonts on your system?** Font.getFontNames()