java - 在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());
}
}
解决方案
推荐阅读
- html - SVG 图像引用策略
- python - 如何修复 Smooch Python API 中重复的消息回复?
- php - 如何修改 Yii2 createCommand() 函数生成的结果
- excel - 如何激活主工作簿并将其放在所有打开的 Excel 文件的前面?
- java - 所有多边形都变得透明,如何修复?
- r - 在 R 中声明 2000 个函数用于遗传算法
- python - (如何)我可以否决内置类型的只读描述符?
- typescript - 我如何告诉 TypeScript 你保证在 `find` 中有一个有效的返回值?
- javascript - 如何显示输入的结果及其排列?
- xcode - Xcode 构建错误 - CocoaPods - ld:警告:找不到目录