Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. package pruebaventanas;
  2.  
  3. import java.net.URL;
  4. import java.util.Optional;
  5. import java.util.ResourceBundle;
  6. import javafx.event.ActionEvent;
  7. import javafx.fxml.FXML;
  8. import javafx.fxml.Initializable;
  9. import javafx.print.Printer;
  10. import javafx.print.PrinterJob;
  11. import javafx.scene.Node;
  12. import javafx.scene.control.Button;
  13. import javafx.scene.control.ChoiceDialog;
  14. import javafx.scene.control.Label;
  15. import javafx.scene.layout.GridPane;
  16. import javafx.stage.Stage;
  17.  
  18. /**
  19. * FXML Controller class
  20. *
  21. * @author Jose Esteve
  22. */
  23. public class VentanaEntradaController implements Initializable {
  24.  
  25.  
  26. private Stage stagePrincipal;
  27.  
  28. @FXML
  29. private GridPane entrada;
  30. @FXML
  31. private Label nombrePelicula;
  32. @FXML
  33. private Label diaPelicula;
  34. @FXML
  35. private Label nombreSala;
  36. @FXML
  37. private Label horaPelicula;
  38. @FXML
  39. private Label numAsientos;
  40. @FXML
  41. private Label precioEntrada;
  42. @FXML
  43. private Button botonImprimir;
  44. @FXML
  45. private Button botonSeleccionar;
  46.  
  47.  
  48. private Printer printer = Printer.getDefaultPrinter();
  49.  
  50.  
  51. public void setStagePrincipal(Stage stagePrincipal) {
  52. this.stagePrincipal = stagePrincipal;
  53.  
  54.  
  55.  
  56. }
  57.  
  58. @FXML
  59. private void salirVentana(ActionEvent event) {
  60. stagePrincipal.close();
  61. }
  62.  
  63. @Override
  64. public void initialize(URL url, ResourceBundle rb) {
  65. }
  66.  
  67.  
  68.  
  69. private void print(Node node)
  70. {
  71. PrinterJob job = PrinterJob.createPrinterJob(printer);
  72. if (job != null)
  73. {
  74. boolean printed = job.printPage(node);
  75. if (printed)
  76. {
  77. job.endJob();
  78. }
  79. else
  80. {
  81. System.out.println("Fallo al imprimir");
  82. }
  83. }
  84. else
  85. {
  86. System.out.println("No puede crearse el job de impresión.");
  87. }
  88. }
  89.  
  90. @FXML
  91. private void imprimir(ActionEvent event) {
  92. print(entrada);
  93. }
  94.  
  95. @FXML
  96. private void seleccionarImpresora(ActionEvent event) {
  97.  
  98. // Selecciona una impresora de las disponibles en la máquina.
  99. ChoiceDialog dialog = new ChoiceDialog(Printer.getDefaultPrinter(),
  100. Printer.getAllPrinters());
  101. dialog.setHeaderText("Seleccionar la impresora!");
  102. dialog.setContentText("Seleccionar una impresora de las disponibles");
  103. dialog.setTitle("Selección Impresora");
  104. Optional<Printer> opt = dialog.showAndWait();
  105. if (opt.isPresent()) {
  106. printer = opt.get();
  107. }
  108. }
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement