gpt4 book ai didi

java - 容器类所有者的子对象必须将组件添加到其父级容器中的问题

转载 作者:行者123 更新时间:2023-11-30 01:39:01 24 4
gpt4 key购买 nike

我在处理 JApplet 中的容器和组件时遇到问题。我没有放置我的代码,因为我认为没有必要。

主类拥有 getContentPane()。

另一个类(我们称之为 class1)拥有 JLayeredPane() 和添加到其中的组件。

另一个类(我们称之为 class2)仅具有要显示的组件。

在init()中,主类添加了class1的JLayeredPane()。

稍后,class1 将其组件添加到其 JLayeredPane() 中,并从 class2 创建一个新对象。

Class2 应该生成可变数量的组件(组件的数量及其属性随时间变化),但无法将它们添加到 class1 的 JLayeredPane() 中。

如何显示 class2 组件?

感谢您的阅读。

最佳答案

Three ways1. Pass JLayeredPane() to the class2's constructor or a method2. Class2 has methods that return the components that Class1 can   add to JLayeredPane()3. Pass Class1's object to class2 which will call Class1's method through   a known interface that Class1 implements (a callback)

关于java - 容器类所有者的子对象必须将组件添加到其父级容器中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1690998/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com