Module_6 (1)
Module_6 (1)
RadioButton JavaFX C
Object Oriented
Programming
Module 6: Introduction to JavaFX
[email protected]
School of Computer Science and Engineering (SCOPE)
VIT-AP University (Besides AP Secretariat) 522237
July 9, 2022
Agenda I
6 JavaFX Label
1 JavaFx
7 JavaFX Button
2 Installation of JavaFx
8 RadioButton
3 JavaFX - Architecture 9 JavaFX CheckBox
4 JavaFx Controls & Descrip- 10 JavaFX TextField
tion 11 JavaFX Menu
5 JavaFX Label 12 JavaFX - Event Handling
JavaFx
JavaFX
Installation of JavaFX
Step 1: Ecplise – Install New Software
Open Eclipse and click on Main Menu -> Help -> Install New
Software .
Installation of JavaFX
Step 2 : Search for e(fx)clipse
Select the Eclipse Release related site (here Neon) for “Work with”
and enter “e(fx)clipse” in the search bar. Wait for the Eclipse to find
e(fx)clipse.
Check the result e(fx)clispe IDE and click on Next.
Installation of JavaFX
Step 3 : Review
Review the items and click on Next.
Installation of JavaFX
Installation of JavaFX
Installation of JavaFX
Step 6 : Verify the installation
To verify if JavaFX has been installed in Eclipse, Open New Project
window (Main Menu -> New -> Project) Java FX should be listed
under wizards.
JavaFX - Architecture
Label
A Label object is a component for placing text.
Button
This class creates a labeled button.
ColorPicker
A ColorPicker provides a pane of controls designed to allow a user to
manipulate and select a color.
CheckBox
A CheckBox is a graphical component that can be in either an
on(true) or off (false) state.
TextField
A TextField object is a text component that allows for the editing of a
single line of text.
PasswordField
A PasswordField object is a text component specialized for password
entry.
Scrollbar
A Scrollbar control represents a scroll bar component in order to
enable user to select from range of values.
Dr. Nikhil Mhala VIT-AP CSE2005 July 9, 2022 13 / 45
JavaFx Installation of JavaFx JavaFX - Architecture JavaFx Controls & Description JavaFX Label JavaFX Label JavaFX Button RadioButton JavaFX C
FileChooser
A FileChooser control represents a dialog window from which the
user can select a file.
ProgressBar
As the task progresses towards completion, the progress bar displays
the task’s percentage of completion.
Slider
A Slider lets the user graphically select a value by sliding a knob
within a bounded interval.
Dr. Nikhil Mhala VIT-AP CSE2005 July 9, 2022 14 / 45
JavaFx Installation of JavaFx JavaFX - Architecture JavaFx Controls & Description JavaFX Label JavaFX Label JavaFX Button RadioButton JavaFX C
javafx.stage.Stage
It is the top level JavaFX container.
javafx.scene.Scene
class is the container for all content in a scene graph
javafx.scene.Node
It is the base class for scene graph nodes
Dr. Nikhil Mhala VIT-AP CSE2005 July 9, 2022 17 / 45
JavaFx Installation of JavaFx JavaFX - Architecture JavaFx Controls & Description JavaFX Label JavaFX Label JavaFX Button RadioButton JavaFX C
Stage:
Scene
Scene
Each stage has a scene.
Javafx.scene.Scene class provides all the methods to deal with a
scene object.
Creating scene is necessary in order to visualize the contents on
the stage.
Scene holds controls (buttons, labels, etc)
Pane
You can put controls in Scenes directly, but we usually Panes for
better layoutExamples: StackPane, BorderPane, HBox, VBox
JavaFX Label
Constructors
Label(): creates an empty Label
Label(String text): creates Label with the supplied text
Label(String text, Node graphics): creates Label with the sup-
plied text and graphics
JavaFX Label
1 import javafx . application . Application ;
2 import javafx . scene . Scene ;
3 import javafx . scene . control . Label ;
4 import javafx . scene . layout . StackPane ;
5 import javafx . stage . Stage ;
6 public class LabelTest extends Application {
7 public void start ( Stage primaryStage ) throws Exception {
8 // TODO Auto - generated method stub
9 Label my_label = new Label ( " This is an example of
Label " ) ;
10 StackPane root = new StackPane () ;
11 Scene scene = new Scene ( root ,300 ,300) ;
12 root . getChildren () . add ( my_label ) ;
13 primaryStage . setScene ( scene ) ;
14 primaryStage . setTitle ( " Label Class Example " ) ;
15 primaryStage . show () ;
16 }
17 public static void main ( String [] args ) {
18 launch ( args ) ;
19 }
20 }
./code/LabelTest.java
Dr. Nikhil Mhala VIT-AP CSE2005 July 9, 2022 23 / 45
JavaFx Installation of JavaFx JavaFX - Architecture JavaFx Controls & Description JavaFX Label JavaFX Label JavaFX Button RadioButton JavaFX C
JavaFX Button
./code/ButtonTest.java
Dr. Nikhil Mhala VIT-AP CSE2005 July 9, 2022 25 / 45
JavaFx Installation of JavaFx JavaFX - Architecture JavaFx Controls & Description JavaFX Label JavaFX Label JavaFX Button RadioButton JavaFX C
RadioButton
./code/RadioButtonTest.java
./code/RadioButtonTest.java
JavaFX CheckBox
The Check Box is used to provide more than one choices to the
user.
It can be used in a scenario where the user is prompted to select
more than one option or the user wants to select multiple
options.
Instantiate javafx.scene.control.CheckBox class to implement
CheckBox
./code/CheckBoxTest.java
Dr. Nikhil Mhala VIT-AP CSE2005 July 9, 2022 30 / 45
JavaFx Installation of JavaFx JavaFX - Architecture JavaFx Controls & Description JavaFX Label JavaFX Label JavaFX Button RadioButton JavaFX C
21
22 HBox root = new HBox () ;
23 root . getChildren () . addAll (l , c1 , c2 , c3 , c4 ) ;
24 root . setSpacing (5) ;
25 Scene scene = new Scene ( root ,800 ,200) ;
26 primaryStage . setScene ( scene ) ;
27 primaryStage . setTitle ( " CheckBox Example " ) ;
28 primaryStage . show () ;
29 }
30 }
./code/CheckBoxTest.java
JavaFX TextField
Text Field is basically used to get the input from the user in the
form of text.
javafx.scene.control.TextField represents TextField.
It provides various methods to deal with textfields in JavaFX.
TextField can be created by instantiating TextField class
./code/TextFieldTest.java
./code/TextFieldTest.java
JavaFX Menu
./code/MenuExample.java
Dr. Nikhil Mhala VIT-AP CSE2005 July 9, 2022 36 / 45
JavaFx Installation of JavaFx JavaFX - Architecture JavaFx Controls & Description JavaFX Label JavaFX Label JavaFX Button RadioButton JavaFX C
21
22 Menu EditMenu = new Menu ( " Edit " ) ;
23 MenuItem EditMenu1 = new MenuItem ( " Cut " ) ;
24 MenuItem EditMenu2 = new MenuItem ( " Copy " ) ;
25 MenuItem EditMenu3 = new MenuItem ( " Paste " ) ;
26 EditMenu . getItems () . addAll ( EditMenu1 , EditMenu2 ,
EditMenu3 ) ;
27 root . setTop ( menubar ) ;
28 FileMenu . getItems () . addAll ( filemenu1 , filemenu2 ,
filemenu3 ) ;
29 menubar . getMenus () . addAll ( FileMenu , EditMenu ) ;
30 primaryStage . setScene ( scene ) ;
31 primaryStage . show () ;
32
33 }
34 }
./code/MenuExample.java
Types of Event
Foreground Events Those events which require the direct
interaction of a user. They are generated as consequences of a
person interacting with the graphical components in a Graphical
User Interface. For example, clicking on a button, moving the
mouse, entering a character through keyboard, selecting an item
from list, scrolling the page, etc.
Background Events Those events that don’t require the
interaction of end-user are known as background events. The
operating system interruptions, hardware or software failure,
timer expiry, operation completion are the example of
background events.
Events in JavaFX
The class named Event of the package javafx.event is the base
class for an event
Mouse Event This is an input event that occurs when a mouse
is clicked. It is represented by the class named MouseEvent. It
includes actions like mouse clicked, mouse pressed, mouse
released, mouse moved, mouse entered target, mouse exited
target, etc.
Key Event This is an input event that indicates the key stroke
occurred on a node. It is represented by the class named
KeyEvent. This event includes actions like key pressed, key
released and key typed.
Drag Event This is an input event which occurs when the
mouse is dragged. It is represented by the class named
DragEvent. It includes actions like drag entered, drag dropped,
drag entered target, drag exited target, drag over, etc.
Window Event This is an event related to window
showing/hiding actions. It is represented by the class named
WindowEvent. It includes actions like window hiding, window
shown,
Dr. Nikhil window hidden, window
Mhala VIT-AP showing, etc.
CSE2005 July 9, 2022 39 / 45
JavaFx Installation of JavaFx JavaFX - Architecture JavaFx Controls & Description JavaFX Label JavaFX Label JavaFX Button RadioButton JavaFX C
Event Handling
./code/EventFiltersExample.java
Dr. Nikhil Mhala VIT-AP CSE2005 July 9, 2022 41 / 45
JavaFx Installation of JavaFx JavaFX - Architecture JavaFx Controls & Description JavaFX Label JavaFX Label JavaFX Button RadioButton JavaFX C
./code/EventFiltersExample.java
Dr. Nikhil Mhala VIT-AP CSE2005 July 9, 2022 42 / 45
JavaFx Installation of JavaFx JavaFX - Architecture JavaFx Controls & Description JavaFX Label JavaFX Label JavaFX Button RadioButton JavaFX C
./code/EventFiltersExample.java
Dr. Nikhil Mhala VIT-AP CSE2005 July 9, 2022 44 / 45
JavaFx Installation of JavaFx JavaFX - Architecture JavaFx Controls & Description JavaFX Label JavaFX Label JavaFX Button RadioButton JavaFX C
Contact:
[email protected]
Landline: 0863-2370961 (Mon-Fri 9 am - 5 pm)
Extension: 5961