重绘主框架
想象一下这种情况。我有一个主 JFrame 窗口和另一个通过单击按钮从主窗口弹出的窗口。如果我想通过单击弹出窗口上的按钮来重新绘制主窗口中的图形,该怎么办?
Imagine this situation. I have main JFrame window and another one which pops out from the main window, by button click. What should I do if I want to repaint graph in main window by clicking the button on the popped up window?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
弹出的窗口需要对主窗口的引用。因此,在弹出窗口的构造函数中,您将接受对主窗口的引用并保留它直到需要为止。
在主窗口中,您可以编写一个方法 update() ,可以从弹出的窗口中调用该方法,并使主窗口相应地重新绘制自身。例如:
在弹出的窗口中:
The popped up window needs a reference to the main window. So in the constructor of the popped up window you will accept a reference to the main window and keep it until needed.
In the main window you can write a method update() that can be called from the popped up window and cause the main window to repaint itself accordingly. For example:
and in the popped up window: