java - 第二次调用类程序中断,Java
问题描述
好吧,请耐心等待我,因为我真的很新。为了保持简单和简短,我有一个具有 jButton(在登录框架上)的类,该类具有应该从另一个类打开框架的操作,如下所示:
if (user.contains("admin") && pass.contains("admin"))
{
Admin adminProz = new Admin();
adminProz.setVisible(true);
frame.setVisible(false);
}
暂时它工作得很好,但后来我回到“登录”页面进行第二次登录尝试,编译器中断......以下是我在控制台中得到的文本:
Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is displayable.
at java.awt.Frame.setUndecorated(Unknown Source)
at prozori.Admin.<init>(Admin.java:50)
at prozori.LoginWin.<init>(LoginWin.java:53)
at prikaz.Logout$1.actionPerformed(Logout.java:36)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
解决方案
在 Frame 可见后,不应调用您尝试调用的方法。
这在java.awt.Frame的文档中有所介绍
摘自 javadoc:
This method can only be called while the frame is not displayable.
Throws:
IllegalComponentStateException - if the frame is displayable
setUndecorated
因此,只需在显示 Frame 之前将其移动到您调用的位置。
推荐阅读
- r - 用 ggplot 绘制一个自由度为 1 的卡方图
- node.js - 使用确认时的 Alexa 递归意图委托
- css - 网格列未按预期换行
- powershell - 这堂课有什么问题?
- android - Firebase Cloud Functions 是否在 Android 的主线程之外运行?
- objective-c - Obj-C - 无法访问 NSArray 中的值?
- swift - 如何将自定义 UIImage 设置为标签栏项目
- ios - 获取图像后如何更新 tableViewCell 高度?
- php - 我的 wordpress 主题 css 文件不工作
- javascript - React es6 中的去抖动