How to Implement timer in a grid java
<p>I am making a timer for the grid so every 5 minuits the grid will fill one full column but it doesn't work for me when i declared the timer. Is there a way in which display the grid with timer and see the grid column being filled each time</p>

<pre><code>import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.Timer;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.Border;
import javax.swing.border.MatteBorder;
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JFrame;

public class TestGrid02 {

    public static void main(String[] args) {
        new TestGrid02();
    }

    public TestGrid02() {
        EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    try {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    }

                    JFrame frame = new JFrame("Testing");
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setLayout(new BorderLayout());
                    frame.add(new TestPane());
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                    frame.revalidate();
                    frame.repaint();
                    //frame.remove(0);
                }
            });
    }

    public class TestPane extends JPanel {
        //         Timer timer = new Timer(500, new ActionListener() {
        //                     @Override
        //                     public void actionPerformed(ActionEvent e) {
        // 
        //                         setLayout(new GridBagLayout());
        //                         GridBagConstraints gbc = new GridBagConstraints();
        //                         for (int row = 0; row &lt; 70; row++) {
        //                             for (int col = 0; col &lt; 60; col++) {
        //                                 gbc.gridx = col;
        //                                 gbc.gridy = row;
        //                                 int i = 0;
        // 
        //                                 CellPane cellPane = new CellPane();
        //                                 Border border = null;
        //                                 if (row &lt; 1) {
        //                                     if (col &lt; 1) {
        //                                         border = new MatteBorder(1, 1, 0, 0, Color.GRAY);
        //                                     } else {
        //                                         border = new MatteBorder(1, 1, 0, 1, Color.GRAY);
        //                                     }
        //                                 } else {
        //                                     if (col &lt; 1) {
        //                                         border = new MatteBorder(1, 1, 1, 0, Color.RED);
        //                                     } else {
        //                                         border = new MatteBorder(1, 1, 1, 1, Color.GRAY);
        //                                     }
        //                                 }
        // 
        //                                 cellPane.setBorder(border);
        //                                 add(cellPane, gbc);
        // 
        //                             }
        //                         }
        //                         timer.start();
        //                     }
        // 
        //                 });

        public TestPane() {

            setLayout(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();

            for(int row = 0; row &lt; 70; row++) {
                for (int col = 0; col &lt; 60; col++) {
                    gbc.gridx = col;
                    gbc.gridy = row;
                    int i = 0;

                    CellPane cellPane = new CellPane();
                    Border border = null;

                    if (row &lt; col) {
                        if (col &lt; row) {
                            border = new MatteBorder(1, 1, 0, 0, Color.GRAY);
                        } else {
                            border = new MatteBorder(1, 1, 0, 1, Color.RED);
                        }
                    } else {
                        if (col &lt; row) {
                            border = new MatteBorder(1, 1, 1, 0, Color.RED);
                        } else {
                            border = new MatteBorder(1, 1, 1, 1, Color.GRAY);
                        }
                    }

                    i++;
                    cellPane.setBorder(border);
                    add(cellPane, gbc);

                }
            }

        }
    };   

    // 
    //     public class TestPane extends JPanel {
    //         public TestPane() {
    //             setLayout(new GridBagLayout());
    // 
    //             GridBagConstraints gbc = new GridBagConstraints();
    //             for (int row = 0; row &lt; 70; row++) {
    //                 for (int col = 0; col &lt; 60; col++) {
    //                     gbc.gridx = col;
    //                     gbc.gridy = row;
    // 
    //                     int increment = 1;
    // 
    //                     CellPane cellPane = new CellPane();
    //                     Border border = null;
    //                     if (row &lt; 1) {
    //                         if (col &lt; 1) {
    //                            
    //                             border = new MatteBorder(1, 1, 0, 0, Color.RED);
    //                             //increment = increment + 1;
    //                         } else {
    //                             
    //                             border = new MatteBorder(1, 1, 0, 1, Color.RED);
    //                             //increment = increment + 1;
    //                         }
    //                     } else {
    //                         if (col &lt; 1) {
    //                             
    //                             border = new MatteBorder(1, 1, 1, 0, Color.RED);
    //                             //increment = increment + 1;
    //                         } else {
    //                             
    //                             border = new MatteBorder(1, 1, 1, 1, Color.RED);
    //                             //increment = increment + 1;
    //                         }
    //                     }
    //                     cellPane.setBorder(border);
    //                     add(cellPane, gbc);
    //                 }
    //             }
    //         }
    // 
    //     }

    public class CellPane extends JPanel {
        private Color defaultBackground;
        public CellPane() {
            addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseEntered(MouseEvent e) {
                        defaultBackground = getBackground();
                        setBackground(Color.BLUE);
                    }

                    @Override
                    public void mouseExited(MouseEvent e) {
                        setBackground(defaultBackground);
                    }
                });
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(50, 50);
        }
    }

}
</code></pre>