0
Есть другие учебники по таким, но они не в очень основных образом. Большинство из них имеют другие аспекты, которые делают новичков, как я, труднее понять ...Как отображать различные файлы fxml на сцене для сценариста? Переключение сцены?
Как переключить сцены или файлы FXML на сцену с помощью кнопки?
Main.Java Класс
package application;
\t
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("Screen 1.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
}
Controller.java Класс
package application;
import javafx.fxml.FXMLLoader;
public class Controller {
\t public void goToScreen2(){
\t \t System.out.println("Going to screen2");
\t \t
\t \t
\t \t
\t }
\t
\t public void goToScreen1(){
\t \t System.out.println("Going to screen1");
\t \t
\t \t
\t \t
\t }
}
экрана 1 FXML файл
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller">
<children>
<Button layoutX="203.0" layoutY="132.0" mnemonicParsing="false" onAction="#goToScreen2" text="Go to screen 2" />
</children>
</Pane>
экран 2 FXML файл
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller">
<children>
<Button layoutX="248.0" layoutY="116.0" mnemonicParsing="false" onAction="#goToScreen1" text="Go to screen 1" />
</children>
</Pane>
Что-то не так с линии 36 в основной –
Вызванный: java.lang.NullPointerException \t при применении. Main.load (Main.java:36) \t at application.Main.start (Main.java:25) –
this "controller.configure (this, loader.getRoot())" –