Please help... my program is meant to count down to zero then exit, but I can't get the button to refresh when the iteration variable has decreased.
package tester; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class ButtonAction { private static void createAndShowGUI() { JFrame frame1 = new JFrame("CountDown"); frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLO SE); final int i = 7; final JButton button = new JButton(" " + i); //Add action listener to button button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { i--; JButton button = new JButton(" " + i); System.out.println("c = " + i); if (i==0) System.exit(0); } }); frame1.getContentPane().add(button); frame1.pack(); frame1.setVisible(true); } public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }