这是加载第二个窗体的代码
public void ToLogin() throws IOException { Message msg = new Message(); msg.show("登录失败"); }
这是第二个窗体的显示代码
public void show(String message) throws IOException { Parent root = FXMLLoader.load(Message.class.getResource("Message.fxml")); Scene scene = new Scene(root); stage.setScene(scene); label.setText(message);//此处抛出空指针异常 stage.initStyle(StageStyle.TRANSPARENT); stage.show(); }
这是Message.fxml文件
<?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.Label?> <?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.text.Font?> <?import javafx.scene.control.Button?> <AnchorPane prefHeight="150.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Message.Message"> <Label fx:id="tips" alignment="CENTER" prefHeight="30.0" prefWidth="400.0" stylesheets="@Message.css" text="提示" textAlignment="CENTER" textFill="WHITE"> <font> <Font size="19.0" /> </font></Label> <Label alignment="CENTER" textAlignment="CENTER" stylesheets="@Message.css" fx:id="label" prefHeight="40.0" prefWidth="400.0" layoutY="50.0" > </Label> <Button prefWidth="100.0" prefHeight="30.0" text="确定" fx:id="Sure" layoutX="80.0" layoutY="110.0" onAction="#Yes" > </Button> <Button prefWidth="100.0" prefHeight="30.0" text="确定" fx:id="Chanl" layoutX="230.0" layoutY="110.0" onAction="#No" > </Button> </AnchorPane>
PHP是世界上最好的语言