Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package application;
- import javafx.application.Application;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.Scene;
- import javafx.stage.Stage;
- public class MainClass extends Application {
- @Override
- public void start(Stage primaryStage) throws Exception {
- primaryStage.setScene(new Scene(FXMLLoader.load(getClass().getResource("FirstPage.fxml"))));
- primaryStage.show();}}
- package application;
- import java.io.IOException;
- import javafx.collections.FXCollections;
- import javafx.collections.ObservableList;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.scene.chart.PieChart;
- import javafx.scene.control.TextField;
- import javafx.stage.Stage;
- public class Controller{
- @FXML
- private TextField XInput;
- @FXML
- private TextField YInput;
- @FXML
- private PieChart PieChart;
- public String[] XI; // Array for X
- public int [] YI; // Array for Y
- public int atm = -1;
- @FXML
- void GetValue(ActionEvent event) { // Write in Arrays
- atm++;
- XI[atm] = XInput.getText();
- YI[atm] = Integer.parseInt(YInput.getText());
- }
- @FXML
- void Stop(ActionEvent event) throws IOException {
- // Load new Stage
- Stage primaryStage = new Stage();
- FXMLLoader fxmlLoader = new FXMLLoader();
- Parent root = fxmlLoader.load(getClass().getResource("SecondPage").openStream());
- Scene scene = new Scene(root);
- primaryStage.setScene(scene);
- primaryStage.show();
- // Create ObservableList
- ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList();
- int i = 0;
- while(i == atm){
- pieChartData.add(new PieChart.Data(XI[i], YI[i]));
- i++;
- }
- // Set PieChart
- PieChart.setData(pieChartData);
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <?import javafx.scene.text.*?>
- <?import java.lang.*?>
- <?import java.util.*?>
- <?import javafx.scene.*?>
- <?import javafx.scene.control.*?>
- <?import javafx.scene.layout.*?>
- <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">
- <children>
- <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" />
- <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;">
- <font>
- <Font size="30.0" />
- </font>
- </TextField>
- <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;">
- <font>
- <Font size="30.0" />
- </font>
- </TextField>
- <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" />
- </children>
- </AnchorPane>
- <?xml version="1.0" encoding="UTF-8"?>
- <?import javafx.scene.control.*?>
- <?import javafx.scene.chart.*?>
- <?import java.lang.*?>
- <?import javafx.scene.layout.*?>
- <?import javafx.scene.layout.AnchorPane?>
- <AnchorPane prefHeight="571.0" prefWidth="744.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
- <children>
- <PieChart fx:id="PieChart" layoutY="7.0" prefHeight="564.0" prefWidth="744.0" />
- </children>
- </AnchorPane>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement