JavaFX, Event-Driven Programming, Inner Classes

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/129

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

130 Terms

1
New cards

Can you load a single Image instance with multiple ImageViews?

Yess.

2
New cards

What is the graphical tool that helps with JavaFX UI design?

SceneBuilder.

3
New cards

What is the declarative language used for constructing JavaFX applications?

FXML.

4
New cards

What is the web component that uses WebKitHTML technology to embed web pages within JavaFX?

WebView.

5
New cards

Can existing Swing applications be updated with JavaFX features?

Yes.

6
New cards

How do you directly draw images in JavaFX?

Using the canvas API.

7
New cards

How do you physically print nodes in JavaFX?

Using the printing API.

8
New cards

Does JavaFX support multitouch handheld devices?

Yess.

9
New cards

What is AWT?

Abstract window toolkit. The original Java desktop application framework.

10
New cards

What is Swing?

Swing replaced AWT as the Java desktop application framework.

11
New cards

What is a build system?

Build systems help with software project management, managing the configuration of dependencies. It automates the process of generating a software build for delivery. There is no need to manually add JAR files.

e.g. Maven, Gradle.

12
New cards

What is the essential framework for writing JavaFX programs?

The javafx.application.Application class.

13
New cards

What files are automatically generated when creating a JavaFX project (in IntelliJ)?

HelloApplication.java

HelloController.java

hello-view.fxml

14
New cards

What static method in the Application class launches the JavaFX application?

launch()

15
New cards

Is the main() method necessary to run a JavaFX program?

Not if you run it from the command line.

16
New cards

What method is overridden in the HelloApplication class (created by IntelliJ upon project creation)?

start()

17
New cards

What is a Stage?

The window for displaying a scene that contains Node objects. It is the parameter of the start() method.

18
New cards

How do you set a scene to a Stage?

stage.setScene(scene);

19
New cards

What is a Scene?

A component tree composed of Node objects.

20
New cards

What is a Node?

A visual component on the UI like a shape, UI control, group, or pane.

21
New cards

What are the 3 basic features each Node has in JavaFX?

1. ID

2. Style class

3. Bounding volume

It can also have effects, transforms, etc.

22
New cards

What is the scene graph?

A set of Nodes in the form of a tree. Basically, it describes the GUI structure.

23
New cards

Can a scene graph have cycles?

No.

24
New cards

What transformations can be applied to Nodes?

Translation: Shifting along the x-axis or y-axis.

Rotation: Rotation about a pivot point.

Scaling: Scales the size of the Node.

Shearing: Rotates one axis so that the x-axis and y-axis are no longer perpendicular.

25
New cards

What is a Parent?

The root Node of the component tree.

26
New cards

What is a branch Node?

A Node that can have children. These Nodes are of type Parent, like Group, Pane, and Control.

27
New cards

What is a leaf Node?

Classes that cannot have children, like Rectangle, Text, and Label.

28
New cards

What is a root Node?

A Node with no Parent Node.

29
New cards

Can a Node occur multiple times in the scene graph?

No.

30
New cards

How do you create Scene objects?

new Scene(Parent root);

new Scene(Parent root, double width, double height);

31
New cards

By default, can the user resize the stage?

Yes.

stage.setResizable(false) disables this.

32
New cards

What is a Shape?

A text, line, circle, rectangle, arc, etc.

33
New cards

What are Panes?

Layouts that organize the Nodes.

34
New cards

What are UI controls?

Interactive Nodes like Labels, CheckBox, RadioButton, etc.

35
New cards

What is a group?

A container that groups collections of nodes. You can apply transformations or effects to a group which automatically apply to all the children Nodes in the group.

36
New cards

What is the inheritance relationship between Node and its child classes?

Node

Parent

Group, Pane, Control

Pane consists of classes ending in "Pane" (except TabPane).

Control consists of UI controls like Button, RadioButton, etc.

Group is just a collection of Nodes.

37
New cards

How do you create a Scene?

new Scene(Parent root);

OR

new Scene(Parent root, double width, double height);

38
New cards

What is a Property?

Values wrapped in classes.

centerXProperty() returns a Property object.

getCenterX() returns the actual value of that Property object.

39
New cards

What is property binding?

Binding a target object (binding property) to a source object (observable object), where a change in the observable object is automatically reflected in the binding property.

40
New cards

What is a binding property?

The target object that reacts to changes.

41
New cards

What is an observable object?

The source object where the changes originate.

42
New cards

What is an ObservableValue?

The whole value that the binding property is set to.

43
New cards

circle.centerYProperty().bind(pane.heightProperty().divide(2));

Which is the binding property? Which is the observable object? Which is the ObservableValue?

Binding property: centerXProperty() and centerYProperty()

Observable object: widthProperty() and heightProperty()

ObservableValue: pane.widthProperty().divide(2) and pane.heightProperty().divide(2)

44
New cards

circle.centerYProperty().bind(pane.heightProperty().divide(2));

What type is centerYProperty()?

A DoubleProperty.

There are similarly IntegerProperty, StringProperty, etc. types.

45
New cards

What do common properties look like in FXML?

-fx-style, -fx-rotate, etc.

46
New cards

How do you paint a node?

Use the immutable Color class, which is a subclass of Paint. Color is IMMUTABLE.

47
New cards

How do you create a Color object?

new Color(double red, double green, double blue, double opacity);

Values range from 0.0 to 1.0.

48
New cards

How can you brighten or darken Colors?

brighter() and darker(). The opacity values remain the same.

49
New cards

How can you set the Font in a UI control?

Use the Font class. Defined by name, weight, posture, and size.

e.g. label.setFont(Font.font("Arial", FontWeight.BOLD, FontPosture.ITALIC, 20));

50
New cards

How do you represent an Image?

The Image class represents an image. Use the ImageView class to display an Image from a local directory or URI.

Image image = new Image("image/us.gif");

ImageView imageView = new ImageView(image);

OR

ImageView imageView = new ImageView();

imageView.setImage(image);

51
New cards

What are the two places you can load an Image from?

A directory or a URI.

52
New cards

How do you create an Image button?

Add a Button, add an ImageView as its child Node, and use button.setGraphic(imageView) to display the Image on the Button.

53
New cards

What are the containers for holding Nodes?

Group and Pane classes.

54
New cards

Are Panes and UI control objects resizable?

Yes.

55
New cards

Are Group, Shape, and text objects resizable?

No.

56
New cards

What Pane subclasses are there?

AnchorPane: Arranges Nodes offset from the top, bottom, left, and right edges of the Pane.

BorderPane: Arranges Nodes in top, bottom, left, right, and center regions.

FlowPane: Arranges Nodes from left to right, wrapping at the edge of the Pane.

GridPane: Arranges Nodes in a grid formation according to row and column indices.

HBox: Arranges Nodes in a single horizontal row.

StackPane: Arranges Nodes stacked on top of each other.

TilePane: Arranges Nodes in a grid of uniformly sized tiles.

VBox: Arranges Nodes in a single vertical row.

57
New cards

How do you add Nodes to a Pane?

pane.getChildren().add(node);

OR

pane.getChildren().addAll(node1, node2, node3);

58
New cards

How can you display Text?

Use the Text class. It displays a String at a starting point (x, y).

59
New cards

What are the basic properties of the Shape class?

fill, stroke, strokeWidth.

stroke and strokeWidth correspond to the color and width of the outline.

60
New cards

What Shape subclasses are there?

Arc

Circle

CubicCurve

Ellipse

Line

Path

Polygon

Polyline

QuadCurve

Rectangle

SVGPath

61
New cards

How can you create a Line?

Use the Line class. It displays a Line using parameters startX, startY, endX, and endY.

62
New cards

What are some commonalities among Shape subclasses?

centerX, centerY, radius.

63
New cards

What Shapes have Arcs?

Rectangle, Circle, Ellipse.

64
New cards

How are Arc angles measured?

In degrees. 0 is the rightmost edge of the circle.

65
New cards

What's the difference between Polygon and Polyline?

Polygon encloses a shape. Polyline doesn't enclose a shape.

66
New cards

What is the inheritance relationship between Node and its UI control child classes?

Node

Parent

Control

Labeled (Label, ButtonBase (Button, CheckBox, ToggleButton (RadioButton)))

TextInputControl (TextArea, TextField (PasswordField))

ComboBoxBase (ComboBox)

ListView

ScrollBar

Slider

67
New cards

Are ImageView and MediaView UI controls?

No, they are not. UI controls are typically interactive.

68
New cards

What is a ButtonBase?

The base class for Buttons, ToggleButtons, and CheckBoxes.

69
New cards

Where do the properties that Buttons and CheckBoxes have come from?

Labeled.

70
New cards

What are the useful methods for Label?

setText("text")

getText()

71
New cards

What are the useful methods for CheckBox, ToggleButton, and RadioButton?

isSelected()

setSelected(true/false)

setDisable(true/false)

72
New cards

What is the difference between parent class ToggleButton and subclass RadioButton?

ToggleButton is rendered as a Button. RadioButton has a dot to show toggle status.

73
New cards

What should you do to ensure ToggleButtons and RadioButtons are in the same group?

Create a ToggleGroup.

setToggleGroup() for each button.

74
New cards

What Node subclass should you use for entering passwords?

Use PasswordField over TextField.

75
New cards

What are the useful methods for TextField, PasswordField, and TextArea?

setText("text")

getText()

setDisable(true/false)

setEditable(true/false)

76
New cards

What Node subclass should you use for entering multiple lines of text?

Use TextArea over multiple TextFields.

77
New cards

What Node subclass should you use for entering dates?

DatePicker.

78
New cards

What Node subclass should you use for implementing a list of items?

ListView. This Node allows you to put items in rows.

79
New cards

What Node subclass should you use for implementing tables (like Excel) in JavaFX?

TableView. This Node is basically a ListView but with support for columns.

80
New cards

What is a ComboBox?

A dropdown list containing items.

81
New cards

How do you add or remove a single item to a ComboBox or ListView?

listview.getItems().add(item)

listview.getItems().remove(item)

82
New cards

How do you add multiple items to a ComboBox or ListView?

listview.getItems().addAll(

Color.RED,

Color.GREEN,

Color.BLUE

);

You can also add an ObservableList of items.

listview.setItems(observableList);

83
New cards

What is a SelectionMode?

An enum used to specify how many items can be selected in Nodes like ComboBox.

SelectionMode.SINGLE

SelectionMode.MULTIPLE

84
New cards

How do you get selected items from Nodes like ComboBox and ListView?

You MUST get the selection model first.

e.g. comboBox.getSelectionModel.getSelecteditem();

85
New cards

What Node subclass should you use for implementing scrolling?

ScrollBar.

86
New cards

What Node subclass should you use for implementing audio and video playing?

MediaPlayer controls the media.

MediaView provides a view of the Media played by MediaPlayer.

87
New cards

What do you call something like a Button that generates an event?

Event source object.

88
New cards

What is an event?

An object created from an event source object.

89
New cards

How do you process events like a button click, mouse movement, or keystrokes?

Use an event handler.

90
New cards

How do you register an event handler with an event source object?

button.setOnAction(handler);

OR

button.setOnMousePressed(handler);

OR

button.setOnKeyPressed(handler);

91
New cards

What two requirements are necessary to be the handler for an action event?

1. Be an instance of the EventHandler interface.

2. Be registered with the event source object (e.g. Button).

92
New cards

What is the inheritance relationship between EventObject and its subclasses?

EventObject

Event (ActionEvent, WindowEvent, InputEvent (MouseEvent, KeyEvent)

93
New cards

How do you identify an event source object?

getSource()

94
New cards

What kind of model does Java use for event handling?

A delegation-based model.

95
New cards

What is fired when a mouse button is pressed, released, clicked, moved, or dragged?

A MouseEvent object. It captures the number of clicks, x and y coordinates, or which button was pressed.

96
New cards

What is fired when a key is pressed, released, clicked, moved, or dragged?

A KeyEvent object. It captures the value of the key and the nature of the event (press or release).

97
New cards

How does a Listener work?

When an Observable object is changed, the Listener is notified by invoking its invalidated(Observable o) method.

98
New cards

What is an inner class?

A class defined within the scope of another class.

99
New cards

What filename format is an inner class compiled into?

OuterClass$InnerClass.class

100
New cards

Is this valid syntax for an inner class?

public void methodName() {

class InnerClass implements SomeInterface {

private String message = "hi";

void printMessage() {

System.out.println(message);

}

Yes.