【发布时间】:2017-06-06 23:19:39
【问题描述】:
以前我正在研究 Java Swing,现在我正在尝试使用 JavaFX。上次我的 Java Swing 代码:
//These line of code is to call method that declared in ContentPage.java
contentPage.adminFeatureEnabled(adminEnabled);
contentPage.managerFeatureEnabled(managerEnabled);
在我的 ContentPage.java 中
//By default, all feature (or tab) are enabled.
//This method is to remove register account if the user login into the system is manager and staff
public void adminFeatureEnabled(boolean a) {
if (!a) {
tabPane.removeTabAt(tabPane.indexOfComponent(registerAccount));
}
}
//This method is to remove register account and purchase order if the user who log into the system is staff
public void managerFeatureEnabled(boolean a) {
if(!a) {
tabPane.removeTabAt(tabPane.indexOfComponent(purchaseOrder));
}
}
在我的代码中:
if (role.equals("admin")){
contentPage.contentFrame.setTitle("Menu - Admin!");
contentPage.disUser.setEditable(true);
contentPage.chgRoles.setEnabled(true);
} else if(role.equals("manager")){
contentPage.contentFrame.setTitle("Menu - Manager!");
contentPage.chgRoles.setSelectedItem("manager");
adminEnabled = false;
}else if (role.equals("staff")){
contentPage.contentFrame.setTitle("Menu - Staff!");
contentPage.chgRoles.setSelectedItem("staff");
adminEnabled = false;
managerEnabled = false;
}
上面的代码会这样执行:
- 当用户使用管理员帐户登录时,所有功能(选项卡)都启用
- 当用户以管理员身份登录时,某些功能(选项卡)将被隐藏
我现在的问题:
我想要在 JavaFX 中具有与上述相同的功能,但我不知道该方法是如何工作的,因为没有一种方法能按我的意愿工作。
谁能帮我解决这个问题?
【问题讨论】: