Hi, the code below is my attempt at a timer to update data pulled from a database. It's not working and I'm very new to java. Does anyone know why? The start/stop buttons are JMenuItems... Thansk >_<.
public class DBMonitor extends javax.swing.JFrame { public final static int SECOND = 1000; private Timer updateTimer; public DBMonitor() { initComponents(); StartButton.addActionListener(new StartUpdating()); StopButton.addActionListener(new StopUpdating()); Timer updateTimer = new Timer(10*SECOND, new ActionListener() { public void actionPerformed(ActionEvent e) { UpdateAll(); Date updateTime = new Date(); timer_Label.setText(updateTime.toString()); System.out.println("Is this working?!"); } }); updateTimer.setInitialDelay(5*ONE_SECOND); //updateTimer.start(); } class StartUpdating implements ActionListener { public void actionPerformed(ActionEvent e) { updateTimer.start(); } } class StopUpdating implements ActionListener { public void actionPerformed(ActionEvent e) { updateTimer.stop(); } }