Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. package application;
  2. import javafx.application.Application;
  3. import javafx.fxml.FXMLLoader;
  4. import javafx.scene.Scene;
  5. import javafx.stage.Stage;
  6. public class MainClass extends Application {
  7. @Override
  8. public void start(Stage primaryStage) throws Exception {
  9. primaryStage.setScene(new Scene(FXMLLoader.load(getClass().getResource("FirstPage.fxml"))));
  10. primaryStage.show();}}
  11.  
  12. package application;
  13. import java.io.IOException;
  14. import javafx.collections.FXCollections;
  15. import javafx.collections.ObservableList;
  16. import javafx.event.ActionEvent;
  17. import javafx.fxml.FXML;
  18. import javafx.fxml.FXMLLoader;
  19. import javafx.scene.Parent;
  20. import javafx.scene.Scene;
  21. import javafx.scene.chart.PieChart;
  22. import javafx.scene.control.TextField;
  23. import javafx.stage.Stage;
  24.  
  25. public class Controller{
  26.  
  27. @FXML
  28. private TextField XInput;
  29. @FXML
  30. private TextField YInput;
  31. @FXML
  32. private PieChart PieChart;
  33. public String[] XI; // Array for X
  34. public int [] YI; // Array for Y
  35. public int atm = -1;
  36.  
  37. @FXML
  38. void GetValue(ActionEvent event) { // Write in Arrays
  39. atm++;
  40. XI[atm] = XInput.getText();
  41. YI[atm] = Integer.parseInt(YInput.getText());
  42. }
  43.  
  44. @FXML
  45. void Stop(ActionEvent event) throws IOException {
  46. // Load new Stage
  47. Stage primaryStage = new Stage();
  48. FXMLLoader fxmlLoader = new FXMLLoader();
  49. Parent root = fxmlLoader.load(getClass().getResource("SecondPage").openStream());
  50. Scene scene = new Scene(root);
  51. primaryStage.setScene(scene);
  52. primaryStage.show();
  53.  
  54. // Create ObservableList
  55. ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList();
  56. int i = 0;
  57. while(i == atm){
  58. pieChartData.add(new PieChart.Data(XI[i], YI[i]));
  59. i++;
  60. }
  61.  
  62. // Set PieChart
  63. PieChart.setData(pieChartData);
  64. }
  65. }
  66.  
  67. <?xml version="1.0" encoding="UTF-8"?>
  68.  
  69. <?import javafx.scene.text.*?>
  70. <?import java.lang.*?>
  71. <?import java.util.*?>
  72. <?import javafx.scene.*?>
  73. <?import javafx.scene.control.*?>
  74. <?import javafx.scene.layout.*?>
  75.  
  76. <AnchorPane id="AnchorPane" prefHeight="410.0" prefWidth="592.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller">
  77. <children>
  78. <Button layoutX="108.0" layoutY="235.0" mnemonicParsing="false" onAction="#GetValue" prefHeight="40.0" prefWidth="376.0" style="-fx-background-color: #FFF; -fx-border-color: #000;" text="Insert" />
  79. <TextField fx:id="YInput" alignment="CENTER" layoutX="108.0" layoutY="154.0" prefHeight="72.0" prefWidth="376.0" promptText="Y" style="-fx-background-color: #FFF; -fx-border-color: #000;">
  80. <font>
  81. <Font size="30.0" />
  82. </font>
  83. </TextField>
  84. <TextField fx:id="XInput" alignment="CENTER" layoutX="108.0" layoutY="74.0" prefHeight="72.0" prefWidth="376.0" promptText="X" style="-fx-background-color: #FFF; -fx-border-color: #000;">
  85. <font>
  86. <Font size="30.0" />
  87. </font>
  88. </TextField>
  89. <Button layoutX="108.0" layoutY="282.0" mnemonicParsing="false" onAction="#Stop" prefHeight="40.0" prefWidth="376.0" style="-fx-background-color: #FFF; -fx-border-color: #000;" text="Stop" />
  90. </children>
  91. </AnchorPane>
  92.  
  93. <?xml version="1.0" encoding="UTF-8"?>
  94.  
  95. <?import javafx.scene.control.*?>
  96. <?import javafx.scene.chart.*?>
  97. <?import java.lang.*?>
  98. <?import javafx.scene.layout.*?>
  99. <?import javafx.scene.layout.AnchorPane?>
  100.  
  101. <AnchorPane prefHeight="571.0" prefWidth="744.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
  102. <children>
  103. <PieChart fx:id="PieChart" layoutY="7.0" prefHeight="564.0" prefWidth="744.0" />
  104. </children>
  105. </AnchorPane>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement