首页 > 解决方案 > 在ActionPerformed之前完成主要功能?

问题描述

对于一个学校项目,我有 2 个不同的界面——一个登录界面和一个“选择”界面。单击登录按钮时,我希望关闭登录界面并打开选择界面。

我遇到的问题是在调用 ActionPerformed 函数时,我的登录界面变为空,即使它仍然显示在屏幕上并且我仍然可以与之交互(?)。

为什么 lface 甚至变为空?我是 JFrame 的新手,所以任何帮助将不胜感激!

这是我的代码

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;

public class testmanager implements ActionListener {
    private SelectionsUserInterface sface;
    private SelectionData sdata = new SelectionData();
    private LoginUserInterface lface;

    @Override
    public void actionPerformed(ActionEvent e) {

        if (e.getActionCommand() == "Login") {
            System.out.println("login button");
            InitializeSelectionInterface();
            DeleteWindow(getLface());
        }

    }

    private void InitializeSelectionInterface() {
        sface = new SelectionsUserInterface(sdata);
    }

    private void DeleteWindow(JFrame window) {
        System.out.println(window);
    }

    public LoginUserInterface getLface() {
        return lface;
    }

    public void setLface(LoginUserInterface lface) {
        this.lface = lface;
    }

}

这是我的主要方法

public class testmain {

    public static void main(String[] args) {

        testmanager m = new testmanager();
        m.setLface(new LoginUserInterface());


    }

}

标签: javaswingjframe

解决方案


推荐阅读