updating a panel 我正在使用 java 为我的作业设计一个程序。 我制作了一个登录框,用户在其中输入名称和密码,然后单击提交或注册。单击后,会出现一个选项 Pane
upEX.(JOptionPane.showMessageDialog(null, "Account registered", "Account",
JOptionPane.INFORMATION_MESSAGE);)
我想知道如何将操作监听器添加到选项 Pane 中的“确定”按钮,该按钮将删除所有内容(用户名、密码、2btns)并将其替换为其他内容?我找到了这个链接:updating a panel基本上只是说使用frame.remove
,然后add
。
另一个问题: 我的 java 文件看起来像这样
class MainFrame extends JFrame {
public MainFrame() {
// All the log in panels buttons are here, etc
}
}
我想知道在同一区域添加新框详细信息或创建一个新类是否会有效?
最佳答案
I was wondering how can I add an actionlistener to the OK button in the option pane that would remove all contents (username,pass,2btns) and replaces it with something else? I found this link: updating a panel which basically just says to use frame.remove and then add.
不要。允许对话框关闭,确定用户采取的操作,显示另一个对话框...
更好的是,创建您自己的 JPanel
,使用 CardLayout
,将所有 View 添加到其中并在它们之间导航。将其放在 JFrame
的实例上...
参见How to Use CardLayout了解更多详情
I was wondering if it would be efficent to add the new box details in the same area or make a new class?
这要看情况。类应该是一个独立的工作单元,专注于完成其设计的任务...如果您的主类正在做更多的工作,那么它应该,那么是的,将逻辑分离到单独的类中
关于java - 使用选项 Pane GUI 替换框架中的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26521718/