There are two fxml files -
Cont1
<?xml version="1.0" encoding="UTF-8"?> <?import java.lang.*?> <?import java.util.*?> <?import javafx.scene.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <AnchorPane id="AnchorPane" prefHeight="347.0" prefWidth="641.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="koko1.Cont1Controller"> <children> <Button fx:id="Matton" layoutX="242.0" layoutY="258.0" onAction="#handleButtonAction" prefHeight="25.0" prefWidth="157.0" text="PUSH" /> <TextField fx:id="text1" layoutX="111.0" layoutY="67.0" prefHeight="25.0" prefWidth="419.0" /> <TextField fx:id="text2" layoutX="111.0" layoutY="109.0" prefHeight="25.0" prefWidth="419.0" /> <TextField fx:id="text4" layoutX="111.0" layoutY="197.0" prefHeight="25.0" prefWidth="419.0" /> <TextField fx:id="text3" layoutX="111.0" layoutY="155.0" prefHeight="25.0" prefWidth="419.0" /> <Button fx:id="close" layoutX="614.0" mnemonicParsing="false" onAction="#close" prefHeight="17.0" prefWidth="30.0" text="Button" /> </children> </AnchorPane> and
Cont2
<?xml version="1.0" encoding="UTF-8"?> <?import java.lang.*?> <?import java.util.*?> <?import javafx.scene.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <AnchorPane id="AnchorPane" prefHeight="240.0" prefWidth="183.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="koko1.Cont1Controller"> <children> <TextField fx:id="fill1" layoutX="9.0" layoutY="37.0" prefHeight="25.0" prefWidth="165.0" /> <TextField fx:id="fill2" layoutX="10.0" layoutY="79.0" prefHeight="25.0" prefWidth="165.0" /> <TextField fx:id="fill4" layoutX="10.0" layoutY="163.0" prefHeight="25.0" prefWidth="165.0" /> <TextField fx:id="fill3" layoutX="9.0" layoutY="118.0" prefHeight="25.0" prefWidth="165.0" /> <Button fx:id="close2" layoutY="214.0" mnemonicParsing="false" onAction="#close2" prefHeight="25.0" prefWidth="28.0" text="Button" /> </children> </AnchorPane> Each has 4 TextField () .
Cont1 has text1 (2,3,4), while Cont2 has fill1 (2,3,4). I need to be able to type in text1, text2, text3 and text4 a line I want, and after pressing Button () (whose name is Matton) (Сont1 closes, Cont2 opens) these lines appeared in Cont2 in the fields fill1, fill2 , fill3 and fill4. All of them are controlled from the controller Cont1Controller .
Cont1controller
import com.sun.scenario.Settings; import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; import javafx.scene.Node; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.input.MouseEvent; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.stage.StageStyle; public class Cont1Controller implements Initializable { @FXML Button Matton; @FXML private Label label; @FXML double xOffset = 0; @FXML double yOffset = 0; @FXML private Button close; @FXML private Button close2; @FXML String a; @FXML String b; @FXML String c; @FXML String d; @FXML private TextField text1; @FXML TextField fill1; @FXML private TextField text2; @FXML TextField fill2; @FXML private TextField text3; @FXML TextField fill3; @FXML private TextField text4; @FXML TextField fill4; @FXML public void close2(ActionEvent event) { Stage stage = (Stage) close2.getScene().getWindow(); stage.close(); } @FXML public void close(ActionEvent event) { Stage stage = (Stage) close.getScene().getWindow(); stage.close(); } @FXML private void handleButtonAction(ActionEvent event) throws IOException { text1 = new TextField(); a = new String(); fill1 = new TextField(); text2 = new TextField(); b = new String(); fill2 = new TextField(); text3 = new TextField(); c = new String(); fill3 = new TextField(); text4 = new TextField(); d = new String(); fill4 = new TextField(); FXMLLoader fxmlLoader2 = new FXMLLoader(getClass().getClassLoader().getResource("windows/Cont2.fxml")); Parent root2 = (Parent) fxmlLoader2.load(); Stage stage2 = new Stage(); Scene mscene = new Scene(root2); //new Settings().start(new Scene(mscene)); stage2.initStyle(StageStyle.TRANSPARENT); stage2.setScene(mscene); a= (String) text1.getUserData(); b= (String) text2.getUserData(); c= (String) text3.getUserData(); d= (String) text4.getUserData(); fill1.setUserData(a); fill2.setUserData(b); fill3.setUserData(c); fill4.setUserData(d); root2.setOnMousePressed((MouseEvent event1) -> { xOffset = event1.getSceneX(); yOffset = event1.getSceneY(); }); root2.setOnMouseDragged((MouseEvent event1) -> { stage2.setX(event1.getScreenX() - xOffset); stage2.setY(event1.getScreenY() - yOffset); }); ((Node)(event.getSource())).getScene().getWindow().hide(); stage2.show(); } @Override public void initialize(URL url, ResourceBundle rb) { // TODO } } Still there is a basic java.class
import javafx.application.Application; import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.TextField; import javafx.scene.input.MouseEvent; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.stage.StageStyle; public class Koko1 extends Application { @FXML double xOffset = 0; @FXML double yOffset = 0; @Override public void start(Stage stage1) throws Exception { FXMLLoader fxmlLoader1 = new FXMLLoader(getClass().getClassLoader().getResource("windows/Cont1.fxml")); Parent root1 = fxmlLoader1.load(); Scene mscene = new Scene(root1); //beauty // Image m_image = new Image("/mini-icon.png"); // stage2.getIcons().addAll(m_image); stage1.setTitle("Banananaaaaa"); stage1.initStyle(StageStyle.TRANSPARENT); root1.setOnMousePressed((MouseEvent event1) -> { xOffset = event1.getSceneX(); yOffset = event1.getSceneY(); }); root1.setOnMouseDragged((MouseEvent event1) -> { stage1.setX(event1.getScreenX() - xOffset); stage1.setY(event1.getScreenY() - yOffset); }); stage1.setScene(mscene); stage1.show(); } /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } }