Using a Timer for a JMenu

I have some example code that creates and displays the date in a label.

Here is the code:

// ClockLabel.java

// An extension of the JLabel class that listens to events from

// a Timer object to update itself with the current date & time.

//

import java.util.Date;

import java.awt.event.*;

import javax.swing.*;

public class ClockLabel extends JLabel implements ActionListener {

public ClockLabel() {

super("" + new Date());

Timer t = new Timer(1000, this);

t.start();

}

public void actionPerformed(ActionEvent ae) {

setText((new Date()).toString());

}

}

I want to make this code work in a JMenu. I can get it to work in a label. I want the time and date displayed in JMenuBar. I created a JPanel and inserted a Label in to a Jmenu, and it does not work. I have tried setTextToolTip, ANd help would be appreciated.

[942 byte] By [wwwlouiea] at [2007-11-27 0:50:49]
# 1
I fixed it myself. Can I award dukes to myself?
wwwlouiea at 2007-7-11 23:21:17 > top of Java-index,Core,Core APIs...
# 2

Heres the code if anybody is interested. It displays the date and time on a JMenuBar:

import java.util.Date;

import java.awt.event.*;

import javax.swing.*;

public class ClockMenu extends JMenu implements ActionListener {

String str = new String();

public ClockMenu() {

super("" + new Date());

Timer t = new Timer(1000, this);

t.start();

}

public void startTimer() {

Timer t = new Timer(1000, this);

t.start();

}

public String getDate() {

// Timer t = new Timer(1000, this);

// t.start();

System.out.println("in getDate() function " + str);

return str;

}

public void actionPerformed(ActionEvent ae) {

str = new Date().toString();

getDate();

setText(((new Date()).toString()));

}

}

wwwlouiea at 2007-7-11 23:21:17 > top of Java-index,Core,Core APIs...