错误:“不推荐使用 Window 类型的 show() 方法”

发布于 2025-01-06 23:10:47 字数 241 浏览 3 评论 0原文

这是一个简单的程序,只需打开 AWT。我正在使用 eclipse,并且我收到上面显示的frame.show(); 的错误。 Eclipse 正在用一条线跨越“显示”。我想要这个程序做的只是显示一个 300px x 300px 的框架窗口。完整代码如下:

    Frame frame = new Frame("Hello World");
    // ...        
    frame.show(); 

this is a simple program to just open an AWT. Im using eclipse and i get the error shown above for frame.show(); Eclipse is crossing "show" with a line. All i want this program to do is just display a 300px by 300px frame window. Heres the full code:

    Frame frame = new Frame("Hello World");
    // ...        
    frame.show(); 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千仐 2025-01-13 23:10:47

show() 方法确实已被弃用。 已弃用意味着您不应该再使用它,因为它已被更好的东西取代,并且将来可能会被删除。在这种情况下,您应该使用 setVisible(true) 来代替。

如果您查看 Javadoc 中是否有已弃用的方法,它通常会告诉您预期的替代方法是什么。

The method show() is, indeed, deprecated. Deprecated means that you're not supposed to use it anymore, as it's been replaced by something better and may be removed in the future. In this case, you're supposed to use setVisible(true) instead.

If you go and look at the Javadoc for a deprecated method, it will generally tell you what the intended replacement is.

虚拟世界 2025-01-13 23:10:47

您现在必须使用 setVisible(true) 来代替。

You now have to use setVisible(true) instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文