[英]How to set the previous jframe visible when current jframe is disposed
我正在制作一个Java gui项目,它由两个框架组成。
问题是,当我从第一帧调用第二帧时,已将其设置为使第一帧可见性设置为false。 问题是如何使用第二帧中的按钮使第一帧再次可见。
我应该放弃这种方法,而是创建一个新的jpanel吗??? jpanel是否具有与jframe类似的功能?
考虑使用CardLayout
。 这样,您可以通过多个UI进行切换,而无需其他框架。 这是使用方法。
编辑:作为纪尧姆张贴在他的评论中, 这从安德鲁的回答也介绍了如何使用的布局。
EDIT2:
当您请求有关我的最新帖子的更多信息时,此类课程的外观如下:
import javax.swing.JFrame;
public abstract class MyFrameManager {
static private JFrame startFrame,
anotherFrame,
justAnotherFrame;
static public synchronized JFrame getStartFrame()
{
if(startFrame == null)
{
//frame isnt initialized, lets do it
startFrame = new JFrame();
startFrame.setSize(42, 42);
//...
}
return startFrame;
}
static public synchronized JFrame getAnotherFrame()
{
if(anotherFrame == null)
{
//same as above, init it
}
return anotherFrame;
}
static public synchronized JFrame getJustAnotherFrame()
{
//same again
return justAnotherFrame;
}
public static void main(String[] args) {
//let's test!
JFrame start = MyFrameManager.getStartFrame();
start.setVisible(true);
//want another window
JFrame another = MyFrameManager.getAnotherFrame();
another.setVisible(true);
//oh, doenst want start anymore
start.setVisible(false);
}
}
这样,您只需实例化每个JFrame
一次,但始终可以通过管理器类访问它们。 之后,您对他们的处理是您的决定。
我还使它成为线程安全的,这对于单例来说至关重要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.