ActionListener完成后如何触发另一个动作监听器?

How to trigger another action listener after completion of ActionListener?

我创建了一个带有 JFrameJPanelJLabelJButton 的 GUI。

 // JFrame
    Jframe f = new JFrame("");
 
 // JButton
    JButton b = new JButton("button1");

 // JLabel
    JLabel l = new JLabel("panel label");

 // JPanel
    JPanel p = new JPanel();

我在面板上添加了按钮和标签。我为按钮添加了两个 ActionListener

 b.addActionListener(e -> {
          //code
        });
 b.addActionListener(e -> {
          //code
        });

我想执行第一个动作侦听器。然后执行另一个。 基本上,我有一些要按顺序在标签中输出的文本。我想让它在面板上显示“你好”然后“再见”。它给我的问题是,它只显示我的第二个 ActionListener“再见”中的文字。

您可以将第二个转换为以下示例。它只显示第二个的原因是 两者都立即运行并且您看到最后一个作为标签。

b.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed( ActionEvent e ) {
            
            Thread t = new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        Thread.sleep(1000);
                        // set your label as Goodbye here
                        // add any other business logic
                    } catch (InterruptedException e1) {
                        e1.printStackTrace();
                    }
                    
                }
                
            });
            t.start(); 
        }
        
    });