如何从CustomComponentController类中引用主ios 控制器循环引用类实例

一家天下网站导航
Copyright&& &&
本站文章大部份源自于网络,其余为本站原创;如果本站文章侵犯了您的权益,请加上方QQ与我们联系。WHAT I HAVE is a standard JavaFX application: Main.java, MainController.java & main.fxml. To add custom component, I created CustomComponentController.java and custom_component_controller.fxml.
PROBLEM is that in CustomComponentController methods I need to reference other methods and standard components from MenuController. I add public static MainC to MainController class body, so that it can be seen from CustomComponentController (MainController.mc.neededMethod()). Then I try to pass everything to it in MainController.initialize() method (mc =) - when debugging this breakpoint, I see this full of components instances, but mc remains with null components afterwards.
QUESTION is how to reference the running instance of MainController to use its components and methods in other classes and to crossreference different custom components from each other? How to clean MainController code from event handlers and assistance methods of components by moving it all to component's own class?
I tried the following approaches, but found no way to make them work without errors:
解决方案 The problem can be solved if you comply the following conditions:
Not only public, but obligatory static MainController mc should be.
Do not forget id in fxml for CustomComponentController: &CustomComponentController fx:id="cc"/&, where cc is the name of the "@FXML imported" CustomComponentController in your MainController class.
Omit parameter fx:controller="main.CustomComponentController" in custom_component_controller.fxml as it results in "Controller value already specified" error (a conflict between main.fxml and custom_component_controller.fxml markup declared controllers).
Put mc = in the beginning of MainController's initialize() method. Before using mc in CustomComponentController class, check if it's not null. It can be null when all components, including CustomComponentController, are instantiated at application startup, but there is no mc instance yet. MainController method initialize() where MainController is instantiated is called after components are loaded. Therefore better practice is to use approach in the next paragraph.
In main.fxml create primary component of the same type that CustomComponentController and with the only fx:id parameter. Replace primary component with your CustomComponentController by creating reloadCustomComponents() method and calling it from CustomComponentController's initialize() method. Do it by adding the following to reloadCustomComponents() method:
customComponentAnchorPane.getChildren().remove(customComponent);
customComponent = new customComponent();
customComponentAnchorPane.getChildren().add(customComponent);
Thus all components can be placed outside CustomComponentController with all their methods and reloaded at the startup of the apllication. All component declarations stay in MainController class and can be reached through MainController mc reference. No duplicate creating of components in detail with parameters is needed.
本文地址: &
我是一个标准的JavaFX应用程序: Main.java,MainController.java& main.fxml 。要添加自定义组件,我创建了 CustomComponentController.java 和 custom_component_controller.fxml 。
PROBLEM是在 CustomComponentController 方法中,我需要引用 MenuController 中的其他方法和标准组件。我将 public static MainC 添加到 MainController 类体,以便可以从 CustomComponentController ( MainController.mc.neededMethod())。然后我尝试在 MainController.initialize()方法( mc = )中传递一切这个断点,我看到这个满的组件实例,但 mc 后面保留空组件。
QUESTION是如何引用 MainController 的运行实例,以便在其他类中使用其组件和方法,以及从每个类中交叉引用不同的自定义组件其他?如何清除 MainController 事件处理程序的代码和组件的辅助方法,将其移动到组件自己的类中?
我尝试了以下方法,但没有找到使它们无错误工作的方法:
MainController ' initialize()方法。在使用CustomComponentController类中的 mc 之前,请检查它不为null。当所有组件(包括 CustomComponentController )在应用程序启动时实例化,但是没有mc实例时,它可以为null。 MainController方法 initialize()其中MainController实例化在组件加载后调用。因此,更好的做法是在下一段使用方法。
在 main.fxml 与 CustomComponentController 和只有 fx:id 参数的类型相同。通过创建 reloadCustomComponents()方法并通过 CustomComponentController
c来调用它,用 CustomComponentController
/ code>' initialize()方法。通过向 reloadCustomComponents()方法添加以下内容来实现:
customComponentAnchorPane.getChildren()。remove(customComponent) ;
customComponent = new customComponent();
customComponentAnchorPane.getChildren()。add(customComponent);
因此,所有组件都可以放置在 CustomComponentController 方法并在重复启动时重新加载。所有组件声明都保留在 MainController 类中,并且可以通过 MainController mc 引用访问。无需使用参数详细重复创建组件。
本文地址: &
扫一扫关注官方微信拒绝访问 |
| 百度云加速
请打开cookies.
此网站 () 的管理员禁止了您的访问。原因是您的访问包含了非浏览器特征(38fa7-ua98).
重新安装浏览器,或使用别的浏览器温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(1075)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'第6章-控制器内部的层',
blogAbstract:'在symfony,控制器层,其中包含的代码连接业务逻辑和表现,是您为分割成不同用途的几个部分组成:
The front controller is the unique entry point to the application.前端控制器是唯一的入口点到应用程序。 It loads the configuration and determines the action to execute.它加载的配置,并决定采取行动来执行。
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:7,
publishTime:0,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}

我要回帖

更多关于 高速usb主控制器 的文章

 

随机推荐