[英]Closing a JFrame from another Method
This Loading window opens and I want it to close once the closeLoadingWindow method runs. 此“加载”窗口打开,我希望它在closeLoadingWindow方法运行后关闭。 I have a button that triggers the closeLoadingWindow method in another class. 我有一个按钮触发另一个类中的closeLoadingWindow方法。 Any help?? 有帮助吗?
import java.awt.BorderLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class LoadingScreen {
public static void createLoadingWindow()
{
JFrame LoadingFrame = new JFrame("Loading");
LoadingFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
JPanel LoadingPanel = new JPanel();
LoadingFrame.add(LoadingPanel, BorderLayout.NORTH);
ImageIcon LoadingGif = new ImageIcon();
JLabel LoadingLabel = new JLabel(LoadingGif);
LoadingPanel.add(LoadingLabel);
LoadingFrame.setVisible(true);
}
public static void closeLoadingWindow()
{
dispose();
}
}
Perhaps if you initialised the Loading Frame as so: 也许是这样初始化加载框架的:
public class LoadingScreen{
JFrame LoadingFrame;
public void createLoadingWindow(){
LoadingFrame = new JFrame("Loading");
...
}
public void closeLoadingWindow(){
LoadingFrame.dispose();
}
}
Or you could pass the Frame Loading frame as a parameter in the close LoadingWindow() method: 或者,您可以在关闭LoadingWindow()方法中将框架加载框架作为参数传递:
public void closeLoadingWindow(JFrame LoadingFrame){
LoadingFrame.dispose();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.