Java返回组件
我的程序有问题。 我正在处理gui,无法让它使用类MenuController中的以下行更改视图:Java返回组件,java,swing,user-interface,components,awt,Java,Swing,User Interface,Components,Awt,我的程序有问题。 我正在处理gui,无法让它使用类MenuController中的以下行更改视图: currentComponent = timeRegController.getView().userRegisterTime(user); 但我有类似的线条,效果很好。currentComponent是程序显示的当前视图的组件 getView()返回名为view的TimeRegistrationPanel 在类TimeRegistrationPanel中,我有以下方法: public Comp
currentComponent = timeRegController.getView().userRegisterTime(user);
但我有类似的线条,效果很好。currentComponent是程序显示的当前视图的组件
getView()返回名为view的TimeRegistrationPanel
在类TimeRegistrationPanel中,我有以下方法:
public Component userRegisterTime(User user) {
JPanel window = new JPanel(new BorderLayout());
return window;
}
我的程序说问题在于:
currentComponent = timeRegController.getView().userRegisterTime(user);
因为类型组件的userRegisterTime()未定义。您需要将返回值强制转换为
TimeRegistrationPanel
类。确保getView()返回TimeRegistrationPanel。我尝试了currentComponent=((对象)timeRegController.getView()).userRegisterTime(用户);和currentComponent=(对象)timeRegController.getView().userRegisterTime(用户);但两者都不起作用。。。?你为什么要投反对票?你知道铸造是怎么工作的吗?也许可以看看Java教程: