Java 它向我显示了我在JPanel上单击的JButton后面的其他组件的内容。发生了什么事?

Java 它向我显示了我在JPanel上单击的JButton后面的其他组件的内容。发生了什么事?,java,swing,user-interface,awt,Java,Swing,User Interface,Awt,点击按钮后,我会看到弹出窗口,它还会显示按钮上的内容 当我将鼠标放在第一个按钮上,然后再放在另一个按钮上时,也会发生这种情况。第一个按钮的文本显示在第二个按钮上 public void actionPerformed(ActionEvent e) { String action = e.getActionCommand(); switch (action) { case "start_game": this.create

点击按钮后,我会看到弹出窗口,它还会显示按钮上的内容

当我将鼠标放在第一个按钮上,然后再放在另一个按钮上时,也会发生这种情况。第一个按钮的文本显示在第二个按钮上

public void actionPerformed(ActionEvent e) {
        String action = e.getActionCommand();

        switch (action) {
        case "start_game":
            this.createPanels();
            break;
        case "sel_hero":
            this.selectHero();
            break;
        case "cal_sel":
            this.clickedCancel();
            break;
        case "start":
            this.clickedStart();
            break;
        case "fight":
            this.clickedFight();
            break;
        case "auto":
            this.clickedAuto();
            break;
        ...
        default:
            this.mainPanel();
            break;
        }
    }
这是创建弹出窗口的方法

 this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setSize(1440, 960);
        this.setResizable(false);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        this.selected = null;
        this.enemySelected = null;
        this.gridLayout = new GridLayout(0, 2);
        this.checks = new HashMap<>();
        this.checks.put(0, true);
        this.checks.put(1, true);
        this.checks.put(2, true);

        this.contentPane = new JPanel(new BorderLayout());
        this.contentPane.setPreferredSize(new Dimension(1376, 600));

        // load game model
        game = new Game();

        // load welcome page
        this.mainPanel();

此.setDefaultCloseOperation(关闭时退出);
这个.setSize(1440960);
此参数为.setresizeable(false);
此.setLocationRelativeTo(空);
此.setVisible(true);
this.selected=null;
this.enemySelected=null;
this.gridLayout=新的gridLayout(0,2);
this.checks=newhashmap();
this.checks.put(0,true);
此。检查。放置(1,true);
此。检查。放置(2,正确);
this.contentPane=newjpanel(newborderlayout());
this.contentPane.setPreferredSize(新维度(1376600));
//负荷博弈模型
游戏=新游戏();
//加载欢迎页面
这个.mainPanel();

有人能给我解释一下发生了什么事吗?

你需要把听众分开。拥有一个单一的单片监听器是自找麻烦,因为它使控制和故障排除变得非常困难。理想情况下,每个按钮都应该有一个操作(出于多种原因,如果需要,我可以进入),然后使用该操作创建按钮。不要发布代码的图像。它很难阅读,不可能复制和测试,不可能搜索,并且排除视力受损的读者。相反,请编辑您的问题,并将实际文本复制到问题的代码块中。要更快获得更好的帮助,请添加或。