OKNO 1
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<children>
<Label layoutX="147.0" layoutY="180.0" text="Podaj zakres:" />
<Label layoutX="147.0" layoutY="259.0" text="Podai ilosc argumentow:" />
<TextField fx:id="zakres" layoutX="324.0" layoutY="176.0" />
<TextField fx:id="args" layoutX="324.0" layoutY="255.0" />
<Button fx:id="przycisk" layoutX="473.0" layoutY="333.0" mnemonicParsing="false" onAction="#akcja" text="Button" />
<Label fx:id="label" layoutX="80.0" layoutY="307.0" prefHeight="62.0" prefWidth="382.0" />
</children>
</Pane>
OKNO 2
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<children>
<Label layoutX="134.0" layoutY="160.0" text="Dane: " />
<TextField fx:id="args2" layoutX="300.0" layoutY="156.0" />
<Label fx:id="wyniki" layoutX="134.0" layoutY="200.0" prefHeight="117.0" prefWidth="314.0" text="Wyniki: " />
<Button fx:id="ok" layoutX="475.0" layoutY="317.0" mnemonicParsing="false" onAction="#akcja2" text="ok" />
<Label fx:id="kom" layoutX="55.0" layoutY="321.0" prefHeight="17.0" prefWidth="345.0" />
</children>
</Pane>
CONTROLLER 1 do 2 fxml
package sample;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.fxml.FXMLLoader;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import java.io.IOException;
public class Controller {
String c; String d;
int niedziala = 0;
@FXML
private TextField zakres;
@FXML
private TextField args;
@FXML
private Label label;
@FXML
private Pane pane1;
@FXML
void akcja() {
try {
c = zakres.getText();
d = args.getText();
int a = Integer.parseInt(c);
niedziala = Integer.parseInt(d);
try {
Parent root1 = FXMLLoader.load(getClass().getResource("sample2.fxml"));
Stage stage = new Stage();
stage.setTitle("My New Stage Title");
stage.setScene(new Scene(root1));
root1.setStyle(pane1.getStyle());
stage.show();
label.setText("Dane: " + c + "\t" + d);
} catch (IOException e) {
e.printStackTrace();
}
} catch (NumberFormatException e) {
label.setText("Nieprawidłowe dane: " + c + "\t" + d);
}
}
@FXML
private TextField args2;
@FXML
private Label wyniki;
@FXML
private Button ok;
@FXML
private Label kom;
@FXML
public void akcja2() {
String parameters = args2.getText();
String[] parameterpParts = parameters.split(" ");
System.out.println(niedziala + " " + parameterpParts[0] + "\n")
}
}
Dlaczego w 1 oknie widać zmienna "niedziala" a jak otwieram 2 okno i chcę sprawdzić czy ilość wprowadzonych argumentów w 2 oknie jest równa liczbie wprowadzonej w 1 oknie? Błąd to Nullpointerexception. Spodziewam się dlaczego, ale nie wiem jak to rozwiązac.