SlideShare uma empresa Scribd logo
1 de 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);

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Mais de 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
 

Último

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Último (20)

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

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);