JFrame 到 Window 类
我想知道这行代码是真的还是有更好的方法? 有人可以帮助我吗?
JFrame jframe=new JFrame()
Window window;
jframe.setUndecorated(true);
window=(Window)jframe; //is this line true?
谢谢。
i want to know which this line code it really true or is there a better way?
can any one help me?
JFrame jframe=new JFrame()
Window window;
jframe.setUndecorated(true);
window=(Window)jframe; //is this line true?
thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这是真的,但你不需要演员阵容。 java.swing.JFrame 是 java.awt.Window 的子类,所以没问题。我找不到应用于 Window 变量的方法不适用于 JFrame 变量的原因。这是不应该发生的,因为 Java 仅对方法调用使用后期绑定。
尝试检查您的代码,检查您是否导入了正确的类,因为我认为您误解了某些内容。
Yes it's true but you don't need the cast. java.swing.JFrame is a child class of java.awt.Window so it's ok. And I can't find a reason why a method applied to your Window variable wouldn't apply to a JFrame variable. It's not supposed to happen as Java only uses late binding for method calls.
Try to review your code, to check if you import the right classes, because I think you're misunderstanding something.
如果您正在使用 JFrame,我的建议是您尝试这样的操作。首先是调用 createAndShowGUI() 的主方法:
然后创建 JFrame 结构:
Interface() 是我创建的类的构造函数,它使用框架作为主窗口,并在其中添加 JPanels,但您可以通过许多其他方式执行。
我想你想要的是显示一个窗口,不是吗?不清楚的是是否要使用 Swing 组件。
If you are using JFrame, my suggestion is that you try something like this. First a main method that calls createAndShowGUI():
Then you create JFrame structure:
Interface() is a constructor of a class I created, that uses frame as main window, and adds JPanels inside it, but you can do in many other ways.
I guess that what you want is to show a window, don't you? What it is not clear is if you want to use Swing components.