Java返回组件
我的程序有问题。 我正在处理 gui,我无法让它用 MenuController 类中的这一行来更改视图:
currentComponent = timeRegController.getView().userRegisterTime(user);
但我有类似的行,效果很好。 currentComponent 一个组件,它是程序正在显示的当前视图。
timeRegController.getView() 返回一个名为 view 的 TimeRegistrationPanel。
在 TimeRegistrationPanel 类中,我有以下方法:
public Component userRegisterTime(User user) {
JPanel window = new JPanel(new BorderLayout());
return window;
}
我的程序说问题出在这一行:
currentComponent = timeRegController.getView().userRegisterTime(user);
因为 userRegisterTime() 对于 Component 类型未定义。
I have a problem with my program.
I'm working on the gui, and I can't get it to change the view with this line in the class MenuController:
currentComponent = timeRegController.getView().userRegisterTime(user);
But I have similar lines, that works just fine. currentComponent an Component that is the current view that the program is showing.
timeRegController.getView() returns a TimeRegistrationPanel called view.
In the class TimeRegistrationPanel I have the following method:
public Component userRegisterTime(User user) {
JPanel window = new JPanel(new BorderLayout());
return window;
}
My program says that the problem lies in the line:
currentComponent = timeRegController.getView().userRegisterTime(user);
because userRegisterTime() is undefined for the type Component.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将返回值转换为
TimeRegistrationPanel
类。You need to cast the return value to your
TimeRegistrationPanel
class.确保 getView() 返回 TimeRegistrationPanel。
Make sure getView() returns TimeRegistrationPanel.