Change JLabel and wait for sometime to exit <p>I want to change the label when I click the button, and then after 3 seconds exit the program. But if I click the button, label does not change. It just exits after 3 seconds. This is my logic</p> <ol> <li><p>Change the label.</p></li> <li><p>Sleep for 3 seconds</p></li> <li><p>Then exit the program.</p> <pre><code>btnNewButton_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Stopping the program."); state.setText("Bye..."); state.setBackground(SystemColor.textHighlight); doStop(); } }); state = new JLabel("Not listening"); state.setForeground(new Color(255, 255, 255)); state.setBackground(new Color(204, 0, 51)); state.setHorizontalAlignment(SwingConstants.CENTER); state.setBounds(10, 222, 488, 24); state.setOpaque(true); frame.getContentPane().add(state); </code></pre> <p><code>public void doStop() { try{ Thread.sleep(3000); } catch(InterruptedException e){ } System.exit(0); } </code></p></li> </ol>