如何在JavaSwing中从另一个类关闭窗口? 标题##1。列表项
我在一个类中编写代码作为设计部分,扩展了JFrame类,在另一个类(不是内部类)中为按钮编写了动作侦听器,最后为main方法编写了单独的类。在listener类中,我关闭当前窗口并打开新窗口。我能打开新窗户。但我不能关闭现有的窗口。请帮助我。(我无法访问setVisible()方法) 谢谢 哈里 这是我的密码如何在JavaSwing中从另一个类关闭窗口? 标题##1。列表项,java,eclipse,swing,Java,Eclipse,Swing,我在一个类中编写代码作为设计部分,扩展了JFrame类,在另一个类(不是内部类)中为按钮编写了动作侦听器,最后为main方法编写了单独的类。在listener类中,我关闭当前窗口并打开新窗口。我能打开新窗户。但我不能关闭现有的窗口。请帮助我。(我无法访问setVisible()方法) 谢谢 哈里 这是我的密码 CredentialsForm .java public CredentialsForm() { btnGetSessionKey.addActionListe
CredentialsForm .java
public CredentialsForm()
{
btnGetSessionKey.addActionListener(new ButSesKeyListener());
btnGoToMessaging.addActionListener(new ButGoToMesListener());
btnGoToMessaging.setFont(new Font("Arial", Font.PLAIN, 12));
btnGetSessionKey.setFont(new Font("Arial", Font.PLAIN, 12));
lblAutomationId.setFont(new Font("Arial", Font.PLAIN, 12));
lblYouSessionKey.setFont(new Font("Arial", Font.PLAIN, 12));
lblEncryptionKey.setFont(new Font("Arial", Font.PLAIN, 12));
lblSingleSignOn.setFont(new Font("Arial", Font.PLAIN, 12));
lblUserName.setFont(new Font("Arial", Font.PLAIN, 12));
lblEmail.setFont(new Font("Arial", Font.PLAIN, 12));
tfGoToMessaging.setColumns(10);
tfGetSessionKey.setColumns(10);
tfEncryptionKey.setColumns(10);
tfSingleSignOn.setColumns(10);
tfUserName.setColumns(10);
tfEmail.setColumns(10);
tfAutomationId.setColumns(10);
initGUI();
}
试试这个
public class FirstFrame extends JFrame {
// your all coding..
}
public class SecondFrame extends JFrame {
public static FirstFrame first;
public static void main(String[] a){
// show the first...
// anywhere you hide first using first.setVisible(false);
}
}
我无法访问setVisible()方法
在ActionListener中,您可以编写通用代码来访问当前窗口:
Component button = (Component)event.getSource();
Window window = SwingUtilities.windowForComponent(button);
window.setVisible(false);
请提供完整的代码。