在我的Java Fx应用程序中,我创建了两个阶段 . 第一阶段是主控制器类中的默认值 HomeController
. 第二个 AddNewEmailController
是通过调用 AddNewEmailController
类中的方法 showNewComposeNewEmail()
创建的 .
新阶段被创建得很好,但我尝试调用的方法都没有,比如关闭 AddNewEmailController
阶段,将在 AddNewEmailController
阶段工作 .
如何让方法起作用?
一旦 AddNewEmailController
阶段打开,我也希望 HomeController
阶段无法访问,就像弹出窗口一样 .
我甚至无法将 AddNewEmailController
阶段送到 iconify ?
谢谢大家 .
The HomeController class:
public class HomeController implements Initializable {
// Initializes the controller class.
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
@FXML
public void windowClose() {
Platform.exit();
}
@FXML
public void showNewComposeNewEmail() throws Exception {
new AddNewEmailController().newnewcomposeNewEmailStage();
}
}
The AddNewEmailController class:
public class AddNewEmailController implements Initializable {
public void setScreenParent(ScreensController screenParent) {
myController = screenParent;
}
// Initializes the controller class.
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
public Stage newComposeNewEmail;
public void newnewcomposeNewEmailStage() throws IOException {
newComposeNewEmail = new Stage();
newComposeNewEmail.initStyle(StageStyle.UNDECORATED);
newComposeNewEmail.initStyle(StageStyle.TRANSPARENT);
Parent newComposeNewEmailRoot = FXMLLoader.load(getClass().getResource("/wakiliproject/Forms/AddNew/NewEmail/NewEmail.fxml"));
StageDraggable.stageDraggable(newComposeNewEmailRoot, newComposeNewEmail);
Scene newComposeNewEmailScene = new Scene(newComposeNewEmailRoot, 590, 670);
newComposeNewEmail.setScene(newComposeNewEmailScene);
newComposeNewEmail.show();
}
@FXML
private void newComposeNewEmailClose() {
newComposeNewEmail.close();
}
@FXML
private void newComposeNewEmailIconify() {
newComposeNewEmail.setIconified(true);
}
}
UPDATE:
NewEmail FXML:
<?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="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="wakiliproject.Forms.AddNew.NewEmail.TryEMailController">
<children>
<Label layoutX="190.0" layoutY="61.0" onMouseClicked="#newComposeNewEmailStageIconify" text="Minimise Window" />
<Label layoutX="300.0" layoutY="61.0" onMouseClicked="#newComposeNewEmailStageClose" text="Close Window" />
</children>
</AnchorPane>
1 回答
在你的fxml中,你的
controller
是fx:controller="wakiliproject.Forms.AddNew.NewEmail.TryEMailController"
在你的代码中,类名是
请使它们相同并重新检查,您的方法将被调用 .
要使新舞台成为家长的孩子,请使用