A class can be de ned inside of another class and it is called a “nested class”
(or an “inner” class).
In general, a nested class is de ned with “private” visibility so that it can be
accessed only by the class containing it.
A nested class can access all instance data and methods of the class
containing it. -- A nested class produces a separate bytecode le.
-- If a nested class called Inside is declared in an outer class called Outside,
two bytecode les will be produced:
Outside.class
Outside$Inside.class
A Java interface is a collection of abstract methods and constants.
An abstract method is a method header without a method body.
Abstract methods – cannot be nal or static (because there is no de nition,
needs to be changed later)
Interface cannot be instantiated.
A class that implements an interface must de ne a de nition for each method in
the interface. Otherwise the class should be declared as abstract.
A class that implements an interface can implements other methods as well.
A class can implement multiple interfaces using commas between the interface
names. A class that implements an interface can implement other methods as
well
In addition to (or instead of) abstract methods, an interface can contain
constants When a class implements an interface, it gains access to all its
constants
The Comparable interface is de ned in the java.lang package and it contains
only one method, compareTo, which takes an object as a parameter and returns
an integer.
Any class that implements the Comparable interface needs to de ne compareTo
method and their instantiated objects become something that can be
compared.
JavaFX application is divided into three main components known as Stage,
Scene and nodes. Stage is a window for displaying a Scene that contains
nodes.
A Scene can contain a Control or a Pane, but not a Shape or an ImageView.
A Node is a visual component such as a button, a shape, an image view, a UI
control or a pane.
A Pane can contain any subtype of Node, such as a shape, a button, etc.
In JavaFX, Layout de nes the way in which the components are to be seen on
the stage.
There are several built-in layout panes which automatically places nodes in a
desired location.
Each built-in layout is represented by a separate class, such as FlowPane,
GridPane, BorderPane, StackPane, HBox, VBox, etc.
All layout classes are inside javafx.scene.layout.* package.
In order to implement a particular layout pane, you will need to instantiate the
class (create an object
from it).
FlowPane arranges the nodes in the pane horizontally from left to right or
vertically from top to bottom in the order in which they were added. When one
row or one column is lled, a new row or column is started automatically.
A GridPane arranges nodes in a grid (matrix) formation. The nodes are placed
in the speci ed column and row indices. Note: Column indices comes before the
row indices and the indices always start from 0.
BorderPane lays out nodes in ve regions: top, left, right, bottom, and center
positions BorderPane uses the setTop(node), setBottom(node),
setLeft(node), setRight(node), and setCenter(node) methods to achieve
this. BorderPane is commonly used as the root of a Scene or another layout
pane.
An HBox lays out its children in a single horizontal row. A VBox lays out its
children in a single vertical column. Di:erent from FlowPane which can layout its
children into multiple rows and columns, an HBox or a VBox can lay out its
children only in one row or one column.
an event is an object that is created when something changes within a
graphical user interface. It can also be de ned as a signal to the program that
something has happened. Such as a button click entering text into a text eld
mouse movement keystroke, etc
A source object that generates an event. Such as button.
An object interested in the event handles it called event handler
To create a Label object.
import javafx.scene.control.Label;
//To create an empty label
Label label1 = new Label();
//create a label with the text element
Label label2 = new Label("Original text");
Most useful methods with a Label object: getText() and setText()
getText() – return the text contents of the label. setText(String text) – speci es
the text caption for the label
A text eld can be used to enter or display a string. To create a TextField object.
import javafx.scene.control.TextField;
TextField tfBrand = new TextField("Dell");
TextField tfQuantity = new TextField("Dell");
TextField tfPrice = new TextField();
TextArea enables the user to enter multiple lines of text. Create a TextArea
object.
import javafx.scene.control.TextArea;
TextArea tAOne = new TextArea();
TextArea tATwo = new TextArea("Original Text");
A combo box, also known as a choice list or drop-down list, contains a list of
items from which the user can choose. A combo box is useful for limiting a
user’s range of choices and avoids the cumbersome validation of data input. To
use ComboBox, you will need to import javafx.scene.control.ComboBox;
Radio buttons, also known as option buttons, enable the user to choose a
single item from a group of choices. In appearance, radio buttons display a
circle that is either lled (if selected) or blank (if not selected).
The ListView class represents a scrollable list of items from which the user can
choose. A list view is a control that basically performs the same function as a
combo box, but it enables the user to choose a single value or multiple values.
JavaFX provides many shape classes for drawing texts, lines, circles,
rectangles, ellipses, arcs, polygons, and polylines.
The Shape class is the abstract base class that de nes the common properties
for all shapes.
Need to import javafx.scene.text.Text; The Text class de nes a node that
displays a string at a starting point (x, y). A Text object is usually placed in a
pane. The pane’s upper-left corner is (0, 0). A string may be displayed in
multiple lines separated by \n
Need to import javafx.scene.shape.Line; A line connects two points with four
parameters startX, startY, endX, and endY.
Need to import javafx.scene.shape.Rectangle; A rectangle is de ned by the
parameters x, y, width, height. The rectangle’s upper-left corner point is at (x,
y)
Need to import javafx.scene.shape.Circle; A circle is de ned by its parameters
centerX, centerY, and radius. You can also change a circle’s center coordinates
and its radius by using the mutators.
Need to import javafx.scene.shape.Ellipse; An ellipse is de ned by its
parameters centerX, centerY, radiusX,radiusY.
A MouseEvent is red whenever a mouse button is pressed, released, clicked,
moved, or dragged on a node or a scene. The MouseEvent object captures the
event, such as the location (the x- and y- coordinates) of the mouse, the
number of clicks associated with it or which mouse button was pressed, etc.
A linear search simply examines each item in the search pool, one at a time,
until either the target is found or until the pool is exhausted This approach does
not assume the items in the search pool are in any particular order We just need
to be able to examine each element in turn (in a linear fashion) We want to de
ne algorithms such that they can search any type of objects, therefore we will
search objects that implement the Comparable interface
The Comparable interface has one method, compareTo, which is designed to
return an integer that speci es the relationship between two objects:
obj1.compareTo(obj2)
This call returns an inetger less than, equal to, or greater than 0 if obj1 is less
than, equal to, or greater than obj2, respectively
If the search pool is sorted, then we use algorithm that is more eGcient than a
linear search A binary search eliminates large parts of the search pool with
each comparison Instead of starting the search at one end, we begin in the
middle Eliminating half of the pool after each comparison
Selection sort orders a list of values by repetitively putting a particular value
into its nal position
More speci cally: nd the smallest value in the list, switch it with the value in the
rst position, nd the next smallest value in the list, switch it with the value in the
second position, repeat until all values are in their proper places
Insertion sort orders a list of values by repetitively inserting a particular value
into a sorted subset of the list
More speci cally, consider the rst item to be a sorted sublist of length 1, insert
the second item into the sorted sublist, shifting the rst item if needed, insert
the third item into the sorted sublist, shifting the other items as needed, repeat
until all values have been inserted into their proper positions
A polymorphic reference is a reference variable that can refer to di:erent types
of objects at di:erent points in time.
Polymorphic references are resolved at run-time, not during compilation
Powered by TCPDF (www.tcpdf.org)