How to capture a click on a JMenuItem dinamically created

I need to know how to capture the event that capture a click in a JMenuItem dinamically created. In this way I could read to the JMenuItem text.Thanks!
[165 byte] By [jperojoa] at [2007-10-2 12:57:15]
# 1

When you create, add a ActionListener to it.

something like:

ActionListener al = new ActionListener() {

public void actionProformed( ActionEvent e ) {

System.out.println( ((JMenuItem)e.getSource() ).getTitle() );

}

}

for( String bob : strings ) {

JMenuItem mi = new JMenuItem( bob );

mi.addActionListener( al );

menuBar.add( mi );

}

mlka at 2007-7-13 10:14:14 > top of Java-index,Java Essentials,Java Programming...
# 2
Thanks, it works!
jperojoa at 2007-7-13 10:14:14 > top of Java-index,Java Essentials,Java Programming...