MAINA MARY NJOKI
CT204/109390/22
TABLE OF CONTENT
 Details for fxml in java
 Event listeners in java
 Implementation of a)inheritance
 b)polymorphism
FXML
 FXML is an XML based language used to design the view/ layout/
interface for the user interface of a JavaFX GUI application.
 It breaks up the view of the project and organizes it.
 It’s similar to HTML as they are both used in designing applications,
only difference is that FXML is used to store and transport data while
HTML is used to display the data.
CONTROLLER CLASS
 A controller class is normally a class that basically controls the flow of the
data, whose object is created by FXML.
 The primary purpose of the controller class is to handle the logic of the user
interface defined in the FXML file. It is also used for;
 Handling events
 Accessing User Interface elements
 Initialization
 Data binding
An example of a corresponding java controller class
 package com.example;
 import javafx.event.ActionEvent;
 import javafx.fxml.FXML;
 import javafx.scene.control.Button;
 public class MyController {
 @FXML
 private Button button;
 @FXML
 private void handleButtonClick(ActionEvent event) {
 System.out.println("Button clicked!");
 }
 }
In this Java class:
 The ‘@FXML’ annotation is used to inject the ‘Button’ defined in the FXML file into
the controller class
 The ‘handleButtonClick’ method is annotated with ‘@FXML’ and is specified in the
FXML file as the method to be called when the button is clicked.
These two files together demonstrate a simple example of using FXML to define
the structure of a JavaFX user interface and a corresponding controller class to
handle events.
EVENT LISTENERS
 Event listeners in JavaFX are used to handle various user interactions, such as button
clicks, mouse movements, key presses, and more.
 Event listeners are associated with specific GUI elements and respond to events
triggered by user actions.
 JavaFX event listeners are implemented as methods in a controller class and are often
annoted with ‘@FXML’.
Examples of event listeners
1.Button click event
 This method is associated with a button in the FXML file using the ‘6’ attribute.
@FXML
private void handleButtonClick(ActionEvent event) {
// Code to execute when the button is clicked
}
2.Mouse Click Event
 this method is associated with a GUI element in the FXML file using the ‘onMouseClicked’ attribute.
@FXML
private void handleMouseClick(MouseEvent event) {
// Code to execute when the mouse is clicked
}
3.Key press event
 It is associated with a GUI element in the FXML file using the ‘onKeyPressed’
attribute
@FXML
private void handleKeyPress(KeyEvent event) {
// Code to execute when a key is pressed
}
INHERITANCE IN JAVA
Inheritance in java enables developers to inherit data members and properties
from one class to another.
IMPORTANT TERMINOLOGY USED IN JAVA INHERITANCE
class-a set of objects which shares common behavior and properties.
Parent class/super class-the class whose features are inherited.
Child class/sub class-class that inherits other class.
Reusability-when a class needs to be created and there is already a class that
exist.
TYPES OF INHERITANCE
Single inheritance
Multiple inheritance
Multi-level inheritance
Hierarchical inheritance
Hybrid inheritance
IMPLEMENTATION OF INHERITANCE
Extends keyword is used for inheritance in java.
Using extends keyword indicates you are derived from an existing class.
Extends refers to increased functionality.
SYNTAX
Class derived-class extends base-class
{
//methods and fields
}
Implementation of inheritance in java
 }

 // Inherited or Sub Class
 class Engineer extends Employee {
 int benefits = 10000;
 }

 // Driver Class
 class Gfg {
 public static void main(String args[])
 {
 Engineer E1 = new Engineer();
 System.out.println("Salary : " + E1.salary
 + "nBenefits : " + E1.benefits);
 }
 }
POLYMORPHISM IN JAVA
 Polymorphism refers to ability to take more than one form.
 Static polymorphism
 Polymorphism that is resolved during compiler time is known as static
polymorphism

Types of Polymorphism
1) Static Polymorphism
2) Dynamic Polymorphism
Dynamic polymorphism
 It is also known as Dynamic Method Dispatch. Dynamic polymorphism is a
process in which a call to an overridden method is resolved at runtime rather,
thats why it is called runtime polymorphism.

mary powerpoint.pptx about IT technology

  • 1.
  • 2.
    TABLE OF CONTENT Details for fxml in java  Event listeners in java  Implementation of a)inheritance  b)polymorphism
  • 3.
    FXML  FXML isan XML based language used to design the view/ layout/ interface for the user interface of a JavaFX GUI application.  It breaks up the view of the project and organizes it.  It’s similar to HTML as they are both used in designing applications, only difference is that FXML is used to store and transport data while HTML is used to display the data.
  • 4.
    CONTROLLER CLASS  Acontroller class is normally a class that basically controls the flow of the data, whose object is created by FXML.  The primary purpose of the controller class is to handle the logic of the user interface defined in the FXML file. It is also used for;  Handling events  Accessing User Interface elements  Initialization  Data binding An example of a corresponding java controller class
  • 5.
     package com.example; import javafx.event.ActionEvent;  import javafx.fxml.FXML;  import javafx.scene.control.Button;  public class MyController {  @FXML  private Button button;  @FXML  private void handleButtonClick(ActionEvent event) {  System.out.println("Button clicked!");  }  }
  • 6.
    In this Javaclass:  The ‘@FXML’ annotation is used to inject the ‘Button’ defined in the FXML file into the controller class  The ‘handleButtonClick’ method is annotated with ‘@FXML’ and is specified in the FXML file as the method to be called when the button is clicked. These two files together demonstrate a simple example of using FXML to define the structure of a JavaFX user interface and a corresponding controller class to handle events.
  • 7.
    EVENT LISTENERS  Eventlisteners in JavaFX are used to handle various user interactions, such as button clicks, mouse movements, key presses, and more.  Event listeners are associated with specific GUI elements and respond to events triggered by user actions.  JavaFX event listeners are implemented as methods in a controller class and are often annoted with ‘@FXML’.
  • 8.
    Examples of eventlisteners 1.Button click event  This method is associated with a button in the FXML file using the ‘6’ attribute. @FXML private void handleButtonClick(ActionEvent event) { // Code to execute when the button is clicked } 2.Mouse Click Event  this method is associated with a GUI element in the FXML file using the ‘onMouseClicked’ attribute. @FXML private void handleMouseClick(MouseEvent event) { // Code to execute when the mouse is clicked }
  • 9.
    3.Key press event It is associated with a GUI element in the FXML file using the ‘onKeyPressed’ attribute @FXML private void handleKeyPress(KeyEvent event) { // Code to execute when a key is pressed }
  • 10.
    INHERITANCE IN JAVA Inheritancein java enables developers to inherit data members and properties from one class to another. IMPORTANT TERMINOLOGY USED IN JAVA INHERITANCE class-a set of objects which shares common behavior and properties. Parent class/super class-the class whose features are inherited. Child class/sub class-class that inherits other class. Reusability-when a class needs to be created and there is already a class that exist. TYPES OF INHERITANCE Single inheritance Multiple inheritance Multi-level inheritance Hierarchical inheritance Hybrid inheritance
  • 11.
    IMPLEMENTATION OF INHERITANCE Extendskeyword is used for inheritance in java. Using extends keyword indicates you are derived from an existing class. Extends refers to increased functionality. SYNTAX Class derived-class extends base-class { //methods and fields }
  • 12.
    Implementation of inheritancein java  }   // Inherited or Sub Class  class Engineer extends Employee {  int benefits = 10000;  }   // Driver Class  class Gfg {  public static void main(String args[])  {  Engineer E1 = new Engineer();  System.out.println("Salary : " + E1.salary  + "nBenefits : " + E1.benefits);  }  }
  • 13.
    POLYMORPHISM IN JAVA Polymorphism refers to ability to take more than one form.  Static polymorphism  Polymorphism that is resolved during compiler time is known as static polymorphism  Types of Polymorphism 1) Static Polymorphism 2) Dynamic Polymorphism
  • 14.
    Dynamic polymorphism  Itis also known as Dynamic Method Dispatch. Dynamic polymorphism is a process in which a call to an overridden method is resolved at runtime rather, thats why it is called runtime polymorphism.