Есть 2 класса. вот первый:
package sample;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import javafx.scene.layout.AnchorPane;
public class InputController {
public double k;
// public double l;
@FXML
private ResourceBundle resources;
@FXML
private URL location;
@FXML
private MenuItem Input;
@FXML
private MenuItem Show;
@FXML
private MenuItem Exit;
@FXML
private TextField x1;
@FXML
private TextField x2;
@FXML
private TextField y1;
@FXML
private TextField y2;
@FXML
private CheckBox length;
@FXML
private CheckBox koef;
@FXML
private Button butt;
@FXML
private AnchorPane In;
@FXML
void initialize() {
Show.setOnAction(event -> {
double X1 = Double.parseDouble((x1.getText()));
double Y1 = Double.parseDouble(y1.getText());
double X2 = Double.parseDouble(x2.getText());
double Y2 = Double.parseDouble(y2.getText());
if (length.isSelected()) {
ShowController len = new ShowController();
double l = Math.sqrt(Math.pow((X2 - X1), 2) + Math.pow((Y2 - Y1), 2));// ОБРАТИТЕ ВНИМАНИЕ НА ЭТУ ПЕРЕМЕННУЮ
len.setLength(l);
}
if (koef.isSelected()) {
k = (Y2 - Y1) / (X2 - X1);
}
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/sample/Show.fxml"));
try {
loader.load();
} catch (IOException e) {
e.printStackTrace();
}
Parent root = loader.getRoot();
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.showAndWait();
});
Exit.setOnAction(actionEvent -> {
System.exit(0);
});
}
}
Вот второй:
package sample;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.MenuItem;
import javafx.stage.Stage;
import javafx.scene.control.TextField;
import org.w3c.dom.ls.LSOutput;
public class ShowController {
Double length;
@FXML
private ResourceBundle resources;
@FXML
private URL location;
@FXML
private MenuItem Input;
@FXML
private MenuItem Show;
@FXML
private MenuItem Exit;
@FXML
private Button buttt;
@FXML
private TextField len;
@FXML
private TextField koef;
public Double getLength() {
return length;
}
public void setLength(Double length) {
this.length = length;
}
@FXML
void initialize() {
//____________________________________________________
Input.setOnAction(actionEvent -> {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/sample/Input.fxml"));
try {
loader.load();
} catch (IOException e) {
e.printStackTrace();
}
Parent root = loader.getRoot();
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.showAndWait();
});
Exit.setOnAction(actionEvent -> {
System.exit(0);
});
//____________________________________________________________________________
}
}
Нужно чтобы значение переменной "l" из первого класса(InputController) можно было вывести в void initialize() во втором(ShowController). Я многое перепробовал, всегда выводило "null"