Implementacion de codigo logico

This commit is contained in:
edgar.juarez 2024-03-20 08:40:23 -06:00
parent 505f56f074
commit 8c4f568a4d
11 changed files with 323 additions and 64 deletions

View File

@ -5,6 +5,12 @@ import javafx.scene.Scene;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/** /**
@ -14,13 +20,44 @@ public class App extends Application {
@Override @Override
public void start(Stage stage) { public void start(Stage stage) {
var javaVersion = SystemInfo.javaVersion(); // Diapositiva d1
var javafxVersion = SystemInfo.javafxVersion(); Titulo t1 = new Titulo("Titulo 1", "Subtitulo 1");
NC_CuadroTexto ct = new NC_CuadroTexto();
ct.agregaTexto("Sentencia 1");
ct.agregaTexto("Sentencia 2");
ct.agregaTexto("Sentencia 3");
ct.agregaTexto("Sentencia 4");
Contenido c1 = new Contenido();
c1.agregaElemento(ct);
ModeloDiapositiva md1 = new ModeloDiapositiva(t1, c1);
Diapositiva d1 = new Diapositiva(md1);
var label = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + "."); // Diapositiva d2
var scene = new Scene(new StackPane(label), 640, 480); ConstructorGraficaBarras cgb = new ConstructorGraficaBarras("Ventas anuales de pasteles", "Año", "Ventas");
stage.setScene(scene); cgb.agregaSerie("2016");
stage.show(); cgb.agregaBarraSerie("2016", "Milky", 5200);
cgb.agregaBarraSerie("2016", "Zanahoria", 2200);
cgb.agregaBarraSerie("2016", "Mostachón", 4800);
cgb.agregaSerie("2017");
cgb.agregaBarraSerie("2017", "Milky", 5400);
cgb.agregaBarraSerie("2017", "Zanahoria", 2500);
cgb.agregaBarraSerie("2017", "Mostachón", 4700);
Contenido c2 = new Contenido();
c2.agregaElemento(cgb.generaGraficaBarras());
Titulo t2 = new Titulo("Titulo 2", "Subtitulo 2");
ModeloDiapositiva md2 = new ModeloDiapositiva(t2, c2);
Diapositiva d2 = new Diapositiva(md2);
Presentacion p = new Presentacion(stage);
p.agregarDiapositiva(d1);
p.agregarDiapositiva(d2);
p.mostrar();
} }
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -4,19 +4,52 @@
*/ */
package com.mycompany.presentador; package com.mycompany.presentador;
import javafx.application.Application; import java.util.HashMap;
import javafx.event.ActionEvent; import java.util.Map;
import javafx.event.EventHandler; import javafx.scene.chart.CategoryAxis;
import javafx.scene.Scene; import javafx.scene.chart.NumberAxis;
import javafx.scene.control.Button; import javafx.scene.chart.XYChart;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/** /**
* *
* @author Jossellin * @author Jossellin
*/ */
public class ConstructorGraficaBarras { public class ConstructorGraficaBarras {
private NC_GraficaBarras gb;
private Map<String, XYChart.Series> series;
public ConstructorGraficaBarras(String Titulo, String ejeX, String ejeY) {
// Da nombre al ejeX
CategoryAxis xAxis = new CategoryAxis();
xAxis.setLabel(ejeX);
// Da nombre al ejeY
NumberAxis yAxis = new NumberAxis();
yAxis.setLabel(ejeY);
gb = new NC_GraficaBarras(xAxis, yAxis);
gb.setTitle(Titulo);
gb.setMinSize(800, 500);
series = new HashMap<>();
}
public void agregaSerie(String nombre) {
XYChart.Series serie = new XYChart.Series();
serie.setName(nombre);
series.put(nombre, serie);
}
public void agregaBarraSerie(String nombreSerie,
String nombreBarra,
double valor) {
XYChart.Series serie = series.get(nombreSerie);
serie.getData().add(new XYChart.Data(nombreBarra, valor));
}
public NC_GraficaBarras generaGraficaBarras() {
for(XYChart.Series serie : series.values()) {
gb.getData().add(serie);
}
return gb;
}
//sin funcionalidad -
} }

View File

@ -3,11 +3,35 @@
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/ */
package com.mycompany.presentador; package com.mycompany.presentador;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
/**
* public class Contenido extends AnchorPane {
* @author Omar López private ObservableList <Node> contenidos;
*/
public class Contenido { public Contenido() {
super();
this.setMaxSize(800, 500);
this.setStyle("-fx-background-color: #FFFFFF;");
this.setLayoutX(0);
this.setLayoutY(200);
contenidos = this.getChildren();
}
public void agregaElemento(NC_Texto t) {
this.contenidos.add(t);
}
public void agregaElemento(NC_CuadroTexto ct) {
this.contenidos.add(ct);
}
public void agregaElemento(NC_GraficaBarras gb) {
this.contenidos.add(gb);
}
} }

View File

@ -0,0 +1,11 @@
package com.mycompany.presentador;
import javafx.scene.Parent;
import javafx.scene.Scene;
public class Diapositiva extends Scene{
public Diapositiva(ModeloDiapositiva md) {
super(md,800,600);
}
}

View File

@ -4,10 +4,26 @@
*/ */
package com.mycompany.presentador; package com.mycompany.presentador;
/** import javafx.scene.Group;
* import javafx.scene.layout.GridPane;
* @author edgar import javafx.scene.layout.VBox;
*/ import javafx.scene.text.Font;
public class ModeloDiapositiva { import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import javafx.scene.text.TextFlow;
public class ModeloDiapositiva extends VBox{
private Titulo areaTitulo;
private Contenido areaContenido;
public ModeloDiapositiva(Titulo t, Contenido c) {
areaTitulo = t;
areaContenido = c;
this.getChildren().add(areaTitulo);
this.getChildren().add(areaContenido);
}
} }

View File

@ -8,6 +8,22 @@ package com.mycompany.presentador;
* *
* @author Roberto * @author Roberto
*/ */
public class NC_CuadroTexto {
import javafx.scene.paint.Color;
import javafx.scene.text.TextFlow;
public class NC_CuadroTexto extends TextFlow {
public NC_CuadroTexto() {
super();
this.setMinSize(800, 600);
this.setLineSpacing(30.0);
}
public void agregaTexto(String punto) {
NC_Texto t = new NC_Texto();
t.setTexto("\n\t* " + punto, 30, Color.BLACK);
this.getChildren().add(t);
}
} }

View File

@ -1,22 +1,21 @@
/* /*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/javafx/FXMain.java to edit this template * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/ */
package com.mycompany.presentador; package com.mycompany.presentador;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/** /**
* *
* @author Jossellin * @author Jossellin
*/ */
public class NC_GraficaBarras {
//sin funcionalidad - import javafx.scene.chart.Axis;
import javafx.scene.chart.BarChart;
public class NC_GraficaBarras extends BarChart {
public NC_GraficaBarras(Axis xAxis, Axis yAxis) {
super(xAxis, yAxis);
}
} }

View File

@ -8,6 +8,28 @@ package com.mycompany.presentador;
* *
* @author Roberto * @author Roberto
*/ */
public class NC_Texto {
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
public class NC_Texto extends Text {
public NC_Texto() {
super();
}
public void setTexto(String t, int tam, Color c) {
this.setFont(Font.font("Arial", FontWeight.NORMAL, tam));
this.setFill(c);
this.setText(t);
}
public void setPosicion(int x, int y) {
this.setLayoutX(x);
this.setLayoutY(y);
}
} }

View File

@ -1,13 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.mycompany.presentador;
/**
*
* @author Jossellin
*/
public class Nc_GraficaBarras {
}

View File

@ -0,0 +1,81 @@
package com.mycompany.presentador;
import java.util.ArrayList;
import java.util.List;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Presentacion {
private Stage controlDiapositivas;
private Stage ventanaDiapositivas;
private List<Diapositiva> diapositivas;
private int diapositivaActual;
public Presentacion(Stage primaryStage) {
controlDiapositivas = primaryStage;
ventanaDiapositivas = new Stage();
diapositivas = new ArrayList<>();
diapositivaActual = 0;
Button btnAtras = new Button("<Atrás>");
btnAtras.setOnAction(
event -> {
if(diapositivaActual > 0) {
diapositivaActual --;
ventanaDiapositivas.setScene(diapositivas.get(diapositivaActual));
}
}
);
Button btnAdelante = new Button("<Adelante>");
btnAdelante.setOnAction(
event -> {
int limiteSuperior = diapositivas.size() - 1;
if(diapositivaActual < limiteSuperior) {
diapositivaActual++;
ventanaDiapositivas.setScene(diapositivas.get(diapositivaActual));
}
}
);
Button btnDetener = new Button("<Detener>");
btnDetener.setOnAction(
event -> {
System.exit(0);
}
);
primaryStage.setOnCloseRequest(
event -> System.exit(0)
);
HBox hboxPane = new HBox(btnAtras, btnDetener, btnAdelante);
hboxPane.setSpacing(20);
Scene control = new Scene(hboxPane);
controlDiapositivas.setTitle("Presentador FX");
controlDiapositivas.setResizable(false);
controlDiapositivas.setScene(control);
}
public void mostrar() {
controlDiapositivas.setAlwaysOnTop(true);
controlDiapositivas.show();
if(this.diapositivas.size()>0) {
ventanaDiapositivas.setScene(diapositivas.get(0));
ventanaDiapositivas.show();
}
}
public void agregarDiapositiva(Diapositiva diapositiva) {
diapositivas.add(diapositiva);
}
}

View File

@ -8,7 +8,40 @@ package com.mycompany.presentador;
* *
* @author Omar López * @author Omar López
*/ */
public class Titulo {
//Comentario import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import javafx.scene.text.TextFlow;
public class Titulo extends TextFlow {
private NC_Texto tTitulo;
private NC_Texto tSubtitulo;
public Titulo() {
super();
this.setMinSize(800, 100);
tTitulo= new NC_Texto();
tSubtitulo = new NC_Texto();
this.getChildren().add(tTitulo);
this.getChildren().add(tSubtitulo);
this.setTextAlignment(TextAlignment.CENTER);
this.setStyle("-fx-background-color: #800000;");
}
public Titulo(String titulo, String subtitulo) {
this();
this.setTitulos(titulo, subtitulo);
}
public void setTitulos(String titulo, String subtitulo) {
tTitulo.setTexto(titulo, 32, Color.WHITE);
tSubtitulo.setTexto("\n"+subtitulo, 28, Color.WHITE);
} }
}