使用另一个类JFrame
我尝试搜索它,但我真的不知道该使用什么术语,所以没有得到任何结果。 基本上,我在一个没有继承任何内容的类中创建了一个 JFrame,但是有 2 个类注入其中,Farmer.java 和 SheepHandlerThread.java 我想使用在初始类中创建的 JFrame 并添加一些额外的形状和对象对此,SheepHandlerThread 处理羊的放牧和行为,而 Farmer.java 控制一个指向鼠标单击位置的方块。
如果我问了一个已经回答的问题,我很抱歉,但我已经开始兜圈子并使自己感到困惑,所以我希望在这里得到一些帮助。询问您是否需要任何澄清。
谢谢, 瑞安
I tried searching for it, but I don't really know what terminology to use, so get no results.
Basically, I have a JFrame created in one class that inherits nothing, But there are then 2 classes that feed into this, Farmer.java and SheepHandlerThread.java I want to use the JFrame created in the initial class and add some extra shapes and objects to it, as SheepHandlerThread handles the Sheep Grazing and Behaviour and Farmer.java controls a square which goes to the position of your mouse click.
Apologies if I asked an already answered question, but I've started to go around in circles and confuse myself, so I'm hoping to get some help here. Ask if you need any clarification.
Thanks,
Ryan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我同意上面的答案。除此之外,我举的例子会对您有所帮助。
I agree with above answer. In addition to that i putting example that will help you.
这两个对象需要以某种方式引用JFrame对象。构造这两个对象时,将 JFrame 对象传递给它们。然后,构造函数可以将帧存储在实例字段中,并在任何时候都可以用它做任何他们想做的事情。
或者这些对象不应该关心UI,而应该只为框架提供服务。在这种情况下,让框架调用这些服务并使用这些服务的结果更新自身。
The two objects need to have a reference to the JFrame object in some way. When constructing the two objects, pass them the JFrame object. The constructor can then store the frame in an instance field, and do whatever they want to do with it whenever they want.
Or these objects shouldn't be concerned with the UI, and should only provide services to the frame. In this case, have the frame call these services and update itself with the result of those services.