SlideShare ist ein Scribd-Unternehmen logo
1 von 18
UNIT 1
JAVAFX 2.0
JavaFX Fundamentals
 The JavaFX 2.0 API is Java’s next generation GUI toolkit for
developers to build rich cross-platform applications.
 JavaFX 2.0 is based on a scene graph paradigm as opposed to the
traditional inmediate mode style rendering.
 Before the creation of JavaFX, the development of rich Internet
applications involved the gathering of many separate libraries and
APIs to achieve highly functional applications.
 These separate libraries include Media, UI controls, Web, 3D, and 2D
APIs.
 Because integrating these APIs together can be rather difficult, the
talented engineers at Sun Microsystems (now Oracle) created a new
set of JavaFX libraries that rool up all the same capabilities under
one roof.
 JavaFX 2.0 is a pure Java (language) API that allows developers to
leverage existing Java libraries and tools.
Installing Required Sotware
 You’ll need to install the following software in
order to get started with JavaFX:
– Java 7 JDK or greater
– JavaFX 2.0 SDK
– Neteans IDE 7.1 or greater
(http://download.oracle.com/javafx/2.0/system_requi
rements/jfxpub-system_requirements.htm)ñ
Creating a new Application
First Steps
 JavaFX applications extend the javafx.application..Application class. The Application
class provides application life cycle functions such as launching and stopping during
runtime.
 In our main() method’s entry point we launch the JavaFX application by simply passing in
the command line arguments to the Application.launch() method.
 Once the application is in a ready state, the framework internals will invoke the start()
method to begin.
 When the start() method is invoked, a JavaFX javafx.stage.Stage object is available for
the developer to use and manipulate.
public void start(Stage primaryStage) {
primaryStage.setTitle("Conceptos JavaFX 2.0");
Group root = new Group();
Scene scene = new Scene(root, 300, 250, Color.WHITE);
primaryStage.setScene(scene);
primaryStage.show();
}
First Steps
 Analogy with a theatre:
– Scene and Stage: There are one or many scenes, and all scenes are performed on a
stage.
 Stage is equivalent to an application window.
 Scene is a content pane capable of holding zero-to-many Node objects.
 A Node is a fundamental base class for all scene graph nodes to be rendered.
 Similar to a tree data structure, a scene graph will contain children nodes by using a
container class Group.
public void start(Stage primaryStage) {
primaryStage.setTitle("Conceptos JavaFX 2.0");
Group root = new Group();
Scene scene = new Scene(root, 300, 250, Color.WHITE);
primaryStage.setScene(scene);
primaryStage.show();
}
First Steps
 Once the child nodes have been added, we set the primaryStage’s (Stage)
scene and call the show() method on the Stage object to show the JavaFX
window.
public void start(Stage primaryStage) {
primaryStage.setTitle("Conceptos JavaFX 2.0");
Group root = new Group();
Scene scene = new Scene(root, 300, 250, Color.WHITE);
primaryStage.setScene(scene);
primaryStage.show();
}
Drawing Text
 To draw text in JavaFX you will be creating a javafx.scene.text.Text
node to be placed on the scene graph (javafx.scene.Scene).
Text text = new Text(100,100,"JavaFX 2.0");//Create a Text node.
//new Text(posX,posY,text to write)
root.getChildren().add(text); //Add a node in the tree.
Text Properties (I)
Rotation
 In the method setRotate(), we have
to specify the rotation angle (in degrees)
Text text = new Text(100,100,"JavaFX 2.0");//Create a Text node.
text.setRotate(45);
root.getChildren().add(text); //Add a node in the tree.
Text Properties (II)
Font. In each Text node you can create and set the font to be rendered onto the
scene grah.
Text text = new Text(105,50, "JavaFX 2.0");
Font f1 = Font.font("Serif", 30);
text.setFont(f1);
Creating Menus (I)
 Menus are standard ways on windowed platform applications to allow users to select
options.
 First, we create an instance of a MenuBar that will contain one to many menu (MenuItem)
objects.
 Secondly, we create menu (Menu) objects that contain one-to-many menu item
(MenuItem) objects and other Menu objects making submenus.
 Third, we create menu items to be added to Menu objects, such as menu (MenuItem).
MenuBar menuBar = new MenuBar(); //Creating a menubar
Menu menu = new Menu(“File”); //Creating first menu
MenuItem menuitem=new MenuItem(“New”); //Creating first item
menu.getItems().add(menuitem); //adding item to menu
menuBar.getMenus().add(menu); //adding menu to menubar
root.getChildren().add(menuBar); //adding menubar to the
//stage
Creating Menus (II)
 For adding an action when you select a menu Item:
menuitem.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
//action
}
});
Creating Menus (III). Example
MenuBar menuBar = new MenuBar();
Menu menu = new Menu("Opcion de Menú");
MenuItem menuitem1=new MenuItem("Opcion 1");
MenuItem menuitem2=new MenuItem("Opcion 2");
menuitem1.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
System.out.println("Opcion 1");
}
});
menuitem2.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
System.out.println("Opcion 2");
}
});
menu.getItems().add(menuitem1);
menu.getItems().add(menuitem2);
menuBar.getMenus().add(menu);
root.getChildren().add(menuBar);
Creating Menus (III). Example
Button (I)
 For adding a button:
 For adding a button with a description text:
 For adding an action for the button:
Button button1 = new Button();
Button button1 = new Button(“Description”);
button1.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
//action
}
});
Button (II)
 For setting the position of the button in the scene layout:
button1.setLayoutX(90);
button1.setLayoutY(150);
Button with images
 We can create a button with a description and a image:
 The ImageView class is a graph node (Node) used to display an already loaded
javafx.scene.image.Image object.
 Using the ImageView node will enable you to crete
special effects on the image to be displayed without
manipulating the physical Image.
Image img = new Image(getClass().getResourceAsStream("fuego.jpg"));
ImageView imgv= new ImageView(img);
imgv.setFitWidth(40); //We set a width for the image
imgv.setFitHeight(40); //We set a height for the image
Button boton1 = new Button("Generar Incendio",imgv);
Label (I)
 For adding a label:
Label l1 = new Label(“Label Description”);
l1.setLayoutX(90); //Setting the X position
l1.setLayoutY(60); //Setting the Y position
root.getChildren().add(l1);

Weitere ähnliche Inhalte

Was ist angesagt?

UIAutomatorでボット作ってみた
UIAutomatorでボット作ってみたUIAutomatorでボット作ってみた
UIAutomatorでボット作ってみた
akkuma
 
Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2
PRN USM
 

Was ist angesagt? (13)

Advance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.SwingAdvance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.Swing
 
Lesson 4
Lesson 4Lesson 4
Lesson 4
 
Creating Alloy Widgets
Creating Alloy WidgetsCreating Alloy Widgets
Creating Alloy Widgets
 
"Android" mobilių programėlių kūrimo įvadas #3
"Android" mobilių programėlių kūrimo įvadas #3"Android" mobilių programėlių kūrimo įvadas #3
"Android" mobilių programėlių kūrimo įvadas #3
 
Chapter 03: Eclipse Vert.x - HTTP Based Microservices
Chapter 03: Eclipse Vert.x - HTTP Based MicroservicesChapter 03: Eclipse Vert.x - HTTP Based Microservices
Chapter 03: Eclipse Vert.x - HTTP Based Microservices
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven Development
 
Advance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handlingAdvance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handling
 
UIAutomatorでボット作ってみた
UIAutomatorでボット作ってみたUIAutomatorでボット作ってみた
UIAutomatorでボット作ってみた
 
Using Weka from Windows prompt
Using Weka from Windows promptUsing Weka from Windows prompt
Using Weka from Windows prompt
 
GUI JAVA PROG ~hmftj
GUI  JAVA PROG ~hmftjGUI  JAVA PROG ~hmftj
GUI JAVA PROG ~hmftj
 
Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2
 
A Series of Fortunate Events - Symfony Camp Sweden 2014
A Series of Fortunate Events - Symfony Camp Sweden 2014A Series of Fortunate Events - Symfony Camp Sweden 2014
A Series of Fortunate Events - Symfony Camp Sweden 2014
 
AWT Packages , Containers and Components
AWT Packages , Containers and ComponentsAWT Packages , Containers and Components
AWT Packages , Containers and Components
 

Andere mochten auch (18)

Como crear un texto
Como crear un textoComo crear un texto
Como crear un texto
 
Como crear un texto copia
Como crear un texto   copiaComo crear un texto   copia
Como crear un texto copia
 
Evaluation Question 6
Evaluation Question 6Evaluation Question 6
Evaluation Question 6
 
Contrastive essay
Contrastive essayContrastive essay
Contrastive essay
 
Unit 1 english
Unit 1 englishUnit 1 english
Unit 1 english
 
Safety signals
Safety signalsSafety signals
Safety signals
 
Display screens
Display screens Display screens
Display screens
 
Como crear un texto
Como crear un textoComo crear un texto
Como crear un texto
 
Unidad o informatica en ingles
Unidad o informatica en inglesUnidad o informatica en ingles
Unidad o informatica en ingles
 
Unidad 2. creación_de_un_escenario_de_simulación_con_jav afx
Unidad 2. creación_de_un_escenario_de_simulación_con_jav afxUnidad 2. creación_de_un_escenario_de_simulación_con_jav afx
Unidad 2. creación_de_un_escenario_de_simulación_con_jav afx
 
Unit 1 informatica en ingles
Unit 1 informatica en inglesUnit 1 informatica en ingles
Unit 1 informatica en ingles
 
Ed and –ing clauses
Ed and –ing clausesEd and –ing clauses
Ed and –ing clauses
 
Information and techonology texts
Information and techonology textsInformation and techonology texts
Information and techonology texts
 
Unit 0 english
Unit 0  englishUnit 0  english
Unit 0 english
 
Unit 2 english
Unit 2  englishUnit 2  english
Unit 2 english
 
First aids 3
First aids 3First aids 3
First aids 3
 
PRESENT PERFECT VS PAST SIMPLE IN ENGLISH
PRESENT PERFECT VS PAST SIMPLE IN ENGLISHPRESENT PERFECT VS PAST SIMPLE IN ENGLISH
PRESENT PERFECT VS PAST SIMPLE IN ENGLISH
 
Makalah media grafis
Makalah media grafisMakalah media grafis
Makalah media grafis
 

Ähnlich wie Unit i informatica en ingles

UNIT 5-JavaFX Event Handling, Controls and Components.pdf
UNIT 5-JavaFX Event Handling, Controls and Components.pdfUNIT 5-JavaFX Event Handling, Controls and Components.pdf
UNIT 5-JavaFX Event Handling, Controls and Components.pdf
SakkaravarthiS1
 
Java Program Photo Viewer1. Write an app called viewer that will .pdf
Java Program Photo Viewer1. Write an app called viewer that will .pdfJava Program Photo Viewer1. Write an app called viewer that will .pdf
Java Program Photo Viewer1. Write an app called viewer that will .pdf
bhim1213
 
The java swing_tutorial
The java swing_tutorialThe java swing_tutorial
The java swing_tutorial
sumitjoshi01
 

Ähnlich wie Unit i informatica en ingles (20)

UNIT 5-JavaFX Event Handling, Controls and Components.pdf
UNIT 5-JavaFX Event Handling, Controls and Components.pdfUNIT 5-JavaFX Event Handling, Controls and Components.pdf
UNIT 5-JavaFX Event Handling, Controls and Components.pdf
 
Java Program Photo Viewer1. Write an app called viewer that will .pdf
Java Program Photo Viewer1. Write an app called viewer that will .pdfJava Program Photo Viewer1. Write an app called viewer that will .pdf
Java Program Photo Viewer1. Write an app called viewer that will .pdf
 
JavaFX ALA ppt.pptx
JavaFX ALA ppt.pptxJavaFX ALA ppt.pptx
JavaFX ALA ppt.pptx
 
L0020 - The Basic RCP Application
L0020 - The Basic RCP ApplicationL0020 - The Basic RCP Application
L0020 - The Basic RCP Application
 
Java AWT and Java FX
Java AWT and Java FXJava AWT and Java FX
Java AWT and Java FX
 
The java swing_tutorial
The java swing_tutorialThe java swing_tutorial
The java swing_tutorial
 
The java rogramming swing _tutorial for beinners(java programming language)
The java rogramming swing _tutorial for beinners(java programming language)The java rogramming swing _tutorial for beinners(java programming language)
The java rogramming swing _tutorial for beinners(java programming language)
 
Selenium interview questions and answers
Selenium interview questions and answersSelenium interview questions and answers
Selenium interview questions and answers
 
From Swing to JavaFX
From Swing to JavaFXFrom Swing to JavaFX
From Swing to JavaFX
 
6 swt programming
6 swt programming6 swt programming
6 swt programming
 
Ios - Introduction to platform & SDK
Ios - Introduction to platform & SDKIos - Introduction to platform & SDK
Ios - Introduction to platform & SDK
 
Swing
SwingSwing
Swing
 
To-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step GuideTo-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step Guide
 
Swings in java
Swings in javaSwings in java
Swings in java
 
28 awt
28 awt28 awt
28 awt
 
Eclipse Tricks
Eclipse TricksEclipse Tricks
Eclipse Tricks
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
Spring hibernate tutorial
Spring hibernate tutorialSpring hibernate tutorial
Spring hibernate tutorial
 
Titanium Appcelerator - Beginners
Titanium Appcelerator - BeginnersTitanium Appcelerator - Beginners
Titanium Appcelerator - Beginners
 
Aspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_csAspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_cs
 

Mehr von Marisa Torrecillas (17)

Unidad 0 (nueva) español
Unidad 0 (nueva) españolUnidad 0 (nueva) español
Unidad 0 (nueva) español
 
Unidad 2(español)
Unidad 2(español)Unidad 2(español)
Unidad 2(español)
 
Unidad 1 (español)
Unidad 1 (español)Unidad 1 (español)
Unidad 1 (español)
 
Unidad 2. creación_de_un_escenario_de_simulación_con_jav afx_español
Unidad 2. creación_de_un_escenario_de_simulación_con_jav afx_españolUnidad 2. creación_de_un_escenario_de_simulación_con_jav afx_español
Unidad 2. creación_de_un_escenario_de_simulación_con_jav afx_español
 
Unidad 2(español)
Unidad 2(español)Unidad 2(español)
Unidad 2(español)
 
Unidad 1 (español)
Unidad 1 (español)Unidad 1 (español)
Unidad 1 (español)
 
Plan de autoproteccion
Plan de autoproteccionPlan de autoproteccion
Plan de autoproteccion
 
Unidad o informatica
Unidad o informaticaUnidad o informatica
Unidad o informatica
 
Fr señales de seguridad
Fr señales de seguridadFr señales de seguridad
Fr señales de seguridad
 
éCrans fr definitif
éCrans fr  definitiféCrans fr  definitif
éCrans fr definitif
 
Fr primeros auxilios-2
Fr primeros auxilios-2Fr primeros auxilios-2
Fr primeros auxilios-2
 
Primeros auxilios
Primeros auxiliosPrimeros auxilios
Primeros auxilios
 
Señales de seguridad1
Señales de seguridad1Señales de seguridad1
Señales de seguridad1
 
Pantallas de visualización 2
Pantallas de visualización 2Pantallas de visualización 2
Pantallas de visualización 2
 
Introduccion a las señales de seguridad
Introduccion a las señales de seguridadIntroduccion a las señales de seguridad
Introduccion a las señales de seguridad
 
Introducción a las pantallas de visualización
Introducción a las pantallas de visualizaciónIntroducción a las pantallas de visualización
Introducción a las pantallas de visualización
 
Introducción a los primeros auxilios
Introducción a los primeros auxiliosIntroducción a los primeros auxilios
Introducción a los primeros auxilios
 

Kürzlich hochgeladen

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Kürzlich hochgeladen (20)

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 

Unit i informatica en ingles

  • 2. JavaFX Fundamentals  The JavaFX 2.0 API is Java’s next generation GUI toolkit for developers to build rich cross-platform applications.  JavaFX 2.0 is based on a scene graph paradigm as opposed to the traditional inmediate mode style rendering.  Before the creation of JavaFX, the development of rich Internet applications involved the gathering of many separate libraries and APIs to achieve highly functional applications.  These separate libraries include Media, UI controls, Web, 3D, and 2D APIs.  Because integrating these APIs together can be rather difficult, the talented engineers at Sun Microsystems (now Oracle) created a new set of JavaFX libraries that rool up all the same capabilities under one roof.  JavaFX 2.0 is a pure Java (language) API that allows developers to leverage existing Java libraries and tools.
  • 3. Installing Required Sotware  You’ll need to install the following software in order to get started with JavaFX: – Java 7 JDK or greater – JavaFX 2.0 SDK – Neteans IDE 7.1 or greater (http://download.oracle.com/javafx/2.0/system_requi rements/jfxpub-system_requirements.htm)ñ
  • 4. Creating a new Application
  • 5. First Steps  JavaFX applications extend the javafx.application..Application class. The Application class provides application life cycle functions such as launching and stopping during runtime.  In our main() method’s entry point we launch the JavaFX application by simply passing in the command line arguments to the Application.launch() method.  Once the application is in a ready state, the framework internals will invoke the start() method to begin.  When the start() method is invoked, a JavaFX javafx.stage.Stage object is available for the developer to use and manipulate. public void start(Stage primaryStage) { primaryStage.setTitle("Conceptos JavaFX 2.0"); Group root = new Group(); Scene scene = new Scene(root, 300, 250, Color.WHITE); primaryStage.setScene(scene); primaryStage.show(); }
  • 6. First Steps  Analogy with a theatre: – Scene and Stage: There are one or many scenes, and all scenes are performed on a stage.  Stage is equivalent to an application window.  Scene is a content pane capable of holding zero-to-many Node objects.  A Node is a fundamental base class for all scene graph nodes to be rendered.  Similar to a tree data structure, a scene graph will contain children nodes by using a container class Group. public void start(Stage primaryStage) { primaryStage.setTitle("Conceptos JavaFX 2.0"); Group root = new Group(); Scene scene = new Scene(root, 300, 250, Color.WHITE); primaryStage.setScene(scene); primaryStage.show(); }
  • 7. First Steps  Once the child nodes have been added, we set the primaryStage’s (Stage) scene and call the show() method on the Stage object to show the JavaFX window. public void start(Stage primaryStage) { primaryStage.setTitle("Conceptos JavaFX 2.0"); Group root = new Group(); Scene scene = new Scene(root, 300, 250, Color.WHITE); primaryStage.setScene(scene); primaryStage.show(); }
  • 8. Drawing Text  To draw text in JavaFX you will be creating a javafx.scene.text.Text node to be placed on the scene graph (javafx.scene.Scene). Text text = new Text(100,100,"JavaFX 2.0");//Create a Text node. //new Text(posX,posY,text to write) root.getChildren().add(text); //Add a node in the tree.
  • 9. Text Properties (I) Rotation  In the method setRotate(), we have to specify the rotation angle (in degrees) Text text = new Text(100,100,"JavaFX 2.0");//Create a Text node. text.setRotate(45); root.getChildren().add(text); //Add a node in the tree.
  • 10. Text Properties (II) Font. In each Text node you can create and set the font to be rendered onto the scene grah. Text text = new Text(105,50, "JavaFX 2.0"); Font f1 = Font.font("Serif", 30); text.setFont(f1);
  • 11. Creating Menus (I)  Menus are standard ways on windowed platform applications to allow users to select options.  First, we create an instance of a MenuBar that will contain one to many menu (MenuItem) objects.  Secondly, we create menu (Menu) objects that contain one-to-many menu item (MenuItem) objects and other Menu objects making submenus.  Third, we create menu items to be added to Menu objects, such as menu (MenuItem). MenuBar menuBar = new MenuBar(); //Creating a menubar Menu menu = new Menu(“File”); //Creating first menu MenuItem menuitem=new MenuItem(“New”); //Creating first item menu.getItems().add(menuitem); //adding item to menu menuBar.getMenus().add(menu); //adding menu to menubar root.getChildren().add(menuBar); //adding menubar to the //stage
  • 12. Creating Menus (II)  For adding an action when you select a menu Item: menuitem.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { //action } });
  • 13. Creating Menus (III). Example MenuBar menuBar = new MenuBar(); Menu menu = new Menu("Opcion de Menú"); MenuItem menuitem1=new MenuItem("Opcion 1"); MenuItem menuitem2=new MenuItem("Opcion 2"); menuitem1.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { System.out.println("Opcion 1"); } }); menuitem2.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { System.out.println("Opcion 2"); } }); menu.getItems().add(menuitem1); menu.getItems().add(menuitem2); menuBar.getMenus().add(menu); root.getChildren().add(menuBar);
  • 15. Button (I)  For adding a button:  For adding a button with a description text:  For adding an action for the button: Button button1 = new Button(); Button button1 = new Button(“Description”); button1.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { //action } });
  • 16. Button (II)  For setting the position of the button in the scene layout: button1.setLayoutX(90); button1.setLayoutY(150);
  • 17. Button with images  We can create a button with a description and a image:  The ImageView class is a graph node (Node) used to display an already loaded javafx.scene.image.Image object.  Using the ImageView node will enable you to crete special effects on the image to be displayed without manipulating the physical Image. Image img = new Image(getClass().getResourceAsStream("fuego.jpg")); ImageView imgv= new ImageView(img); imgv.setFitWidth(40); //We set a width for the image imgv.setFitHeight(40); //We set a height for the image Button boton1 = new Button("Generar Incendio",imgv);
  • 18. Label (I)  For adding a label: Label l1 = new Label(“Label Description”); l1.setLayoutX(90); //Setting the X position l1.setLayoutY(60); //Setting the Y position root.getChildren().add(l1);