当前位置: 移动技术网 > IT编程>开发语言>Java > javafx中多场景的切换

javafx中多场景的切换

2019年03月14日  | 移动技术网IT编程  | 我要评论

edd-202,石家庄高速,源远流长造句

0.前言

  前段时间在做javafx的应用程序,遇到一些坑。以本文记录之。(如有更好的解决办法欢迎评论,本人小白,轻喷)

1.问题

  按照官方的中文文档,成功的运行了单一界面的表单登录。于是想自己试试多界面跳转,给按钮添加事件响应。可是怎么操作都报错,百度了许久没有解决办法。后来google后找到了一个合适的解决办法。

2.代码

  下面一段代码是我主程序界面fxml文件中,创建字符串的按钮

 <button fx:id="createstring" defaultbutton="true" layoutx="216.0" layouty="159.0" mnemonicparsing="false" onaction="#createstringoperation" prefheight="58.0" prefwidth="154.0" text="创建字符串">
               <font>
                  <font size="23.0" />
               </font>
            </button>

   这是我通过下面方法解决的通过一个按钮动作弹出另一个界面。其中createstring.fxml是弹出窗口的界面布局。

 //创建字符串
    @fxml protected void createstringoperation(actionevent event) throws ioexception {
        parent operation_parent = fxmlloader.load(getclass().getresource("createstring.fxml"));
        scene operation_creating_scene = new scene(operation_parent);
        stage createoperation_stage = (stage) ((node) event.getsource()).getscene().getwindow();
        createoperation_stage.hide();
        createoperation_stage.setscene(operation_creating_scene);
        createoperation_stage.show();

    }

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网