1 / 6100%
CSE205
Object-Oriented Programming and
Data Structures
GUI
(Graphical User Interface)
Introduction
The Color Class
You need to import the following class in order to use Color:
import javafx.scene.paint.Color;
A color instance can be constructed using the following constructor.
r, g, b represents red, green and blue color which value is between 0.0 to
1.0.
public Color(double r, double g, double b, double opacity);
For example:
Color color = new Color(0.25, 0.14, 0.333, 0.51);
The Color class is immutable.
Once a Color object is created, its properties cannot be changed.
You can use one of the many standard colors such as
RED, BLUE, BLACK, BROWN, BEIGE,CYAN, DARKGRAY,
GOLD, GRAY, GREEN, LIGHTGRAY, MAGENTA, NAVY,
ORANGE, PINK, RED, SILVER, WHITE, and YELLOW
defined as constants in the Color class.
Example #1: the following code, for instance, sets the text color to
red:
Label label1 = new Label(“CSE205 GUI”);
label1.setTextFill(Color.RED);
Example #2: the following code fill color of a circle to blue:
circle.setFill(Color.BLUE);
You need to import the following class in order to use
Font
import javafx.scene.text.Font;
You can set fonts for rendering the text. A Font instance
can be constructed using its constructors or using its static
methods. for example:
See Example : FontDemo.java
The Font Class
Powered by TCPDF (www.tcpdf.org)
Students also viewed