gpt4 book ai didi

java - JOptionPane.showInputDialog 显示两次

转载 作者:行者123 更新时间:2023-11-29 05:43:36 25 4
gpt4 key购买 nike

当我按下投诉框时,每个输入对话框都显示两次...我尝试删除 boxComplain.setSelected(true) 并且它有效(只显示一次)但是这使得复选框在我输入输入后消失.

    class CheckBoxListener implements ItemListener {  

public void itemStateChanged(ItemEvent event) {
if(boxComplain.isSelected())

{
ab=JOptionPane.showInputDialog("Enter Reason of Complain: ");
ac=JOptionPane.showInputDialog("Enter What The Complain is About: ");
label4.setText("Complain request");
boxComplain.setSelected(true);
}
}
}

最佳答案

ItemListener 被调用两次——一次是在原始选择被更改时,第二次是在新选择被注册时。考虑改用 ActionListener。

另一个技巧是删除和添加 ItemListener:

     public void itemStateChanged(ItemEvent event) {
if(boxComplain.isSelected()) {
ab=JOptionPane.showInputDialog("Enter Reason of Complain: ");
ac=JOptionPane.showInputDialog("Enter What The Complain is About: ");
label4.setText("Complain request");
boxComplain.removeItemListener(this);
boxComplain.setSelected(true);
boxComplain.addItemListener(this);
}
}

关于java - JOptionPane.showInputDialog 显示两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16623650/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com