Escolar Documentos
Profissional Documentos
Cultura Documentos
Actividad indivudual
Sesin: 5
cuadros de texto
etiquetas
fondo del Pane
Aplica ambos estilos de CSS:
Inline
CSS File
Cdigo Fuente:
import javafx.application.Application;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.event.*;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
@Override
public void start(Stage stage) throws Exception {
//Crea el layout
GridPane grid = new GridPane();
//Agrega eventos
EventHandler<ActionEvent> action = new EventHandler<ActionEvent>(){
public void handle(ActionEvent event) {
String input = txtSrc.getText();
Double d = 0d;
if( !input.isEmpty()){
try{
d = Double.parseDouble(input);
}catch(NumberFormatException nfe){
Alert alert = new Alert(AlertType.ERROR);
alert.setHeaderText("Entrada invalida, ingresa numeros
reales");
alert.show();
return;
}
if(choiceBox.getSelectionModel().getSelectedItem().startsWith("Celsius")){
lSrc.setText("C");
lTgt.setText("F");
txtTgt.setText((d * (9d/5) +32) + "");
}else
if(choiceBox.getSelectionModel().getSelectedItem().startsWith("Fahrenheit")){
lSrc.setText("F");
lTgt.setText("C");
txtTgt.setText(((d - 32) * (5d/9)) + "");
}
}else{
if(choiceBox.getSelectionModel().getSelectedItem().startsWith("Celsius")){
Pg. 4
lSrc.setText("C");
lTgt.setText("F");
}else
if(choiceBox.getSelectionModel().getSelectedItem().startsWith("Fahrenheit")){
lSrc.setText("F");
lTgt.setText("C");
}
}
}
};
choiceBox.setOnAction(action);
btnConvert.setOnAction(action);
btnClose.setOnAction(new EventHandler<ActionEvent>(){
public void handle(ActionEvent event) {
Platform.exit();
}
});
btnClose.setStyle(
"-fx-font-size: 24px;"
+ "-fx-font-weight: bold;"
+ "-fx-background-color: red;"
+ "-fx-border-style: solid inside;"
+ "-fx-border-width: 2;"
+ "-fx-border-insets: 5;"
+ "-fx-border-radius: 5;"
+ "-fx-border-color: orange;"
);
//Creando la escena
Scene scene = new Scene(grid);
scene.getStylesheets().add(getClass().getResource("Style.css").toExternalForm());
stage.setTitle("Convertidor de temperaturas");
stage.setScene(scene);
stage.show();
}
Pg. 5
Ejecucin:
CONCLUSIONES/REFLEXIN
Este ejercicio me ayudo a practicar como crear interfaces grficas con javafx,
aprend un poco de la sintaxis de CSS y como usarlo en java de manera inline y
por medio de un archivo.