WEEK 9 - JAVAFX AND EVENT HANDLING-DRIVEN PROGRAMMING Flashcards
What is procedural programming?
Procedural programming is executed in procedural order.
What is event-driven programming?
In event-driven programming, code is executed upon
activation of events.
What is an event?
An event can be defined as a type of
signal to the program that something
has happened.
The event is generated by external user
actions such as mouse movements,
mouse clicks, or keystrokes.
What is a listener class?
A listener class is designed specifically
to create a listener object for a GUI
component (e.g., a button). It will not
be shared by other applications. So, it
is appropriate to define the listener
class inside the frame class as an
inner class.
What is an inner class?
An inner class is a member of another class.
An inner class can reference the data and
methods defined in the outer class in which it
nests, so you do not need to pass the
reference of the outer class to the constructor
of the inner class.
What are some advantages of an inner class?
In some applications, you can
use an inner class to make programs
simple.
What are the rules surrounding Inner Class?
An inner class can be declared public,
protected, or private subject to the
same visibility rules applied to a
member of the class.
An inner class can be declared static.
A static inner class can be accessed
using the outer class name. A static
inner class cannot access nonstatic
members of the outer class
What must the Anonymous Inner Class do?
- Extend a superclass or implement an interface but it cannot have an explicit extends or implements clause.
- Implement all the abstract methods in the superclass/interface.
- Uses the no-arg constructor from its superclass to create an instance. If it implements an interface, the constructor is Object().
- Is compiled into a class named OuterClassName$n.class. For example, if the outer class Test has two anonymous inner classes, these two classes are compiled into Test$1.class and Test$2.class.
How do you declare an anonymous inner class?
new SuperClassName/InterfaceName() {
// Implement or override methods in superclass or interface
// Other methods if necessary
}
What is Lambda Expressions?
A way to simplify code.
Lambda expression is a new feature in Java 8.
Lambda expressions can be viewed as an
anonymous method with a concise syntax. For
example, the following code in (a) can be greatly
simplified using a lambda expression in (b) in three
The basic syntax for lambda expression is what?
The basic syntax for a lambda expression is
either
(type1 param1, type2 param2, …) ->
expression
or
(type1 param1, type2 param2, …) -> {
statements; }
What is a Single Abstract Method (SAM) Interface?
The statements in the lambda expression is all
for that method. If it contains multiple methods,
the compiler will not be able to compile the
lambda expression. So, for the compiler to
understand lambda expressions, the interface
must contain exactly one abstract method. Such
an interface is known as a functional interface,
or a Single Abstract Method (SAM) interface.
AnonymousHandlerDemo Run
Why would you use a listener for an observable objects?
You can add a listener to process a value change in an observable object.
What is an observable object?
An instance of Observable.
What do the PathTransition and FadeTransition do?
PathTransition and FadeTransition define specialized
animations.