JButton myButton = new JButton("Example");
myButton.addActionListener(whoeverHandlesEvents);
text.add(myButton);
where whoeverHandlesEvents implements the ActionListener interface. could be your panel, inner class, anonymous class, or none of the above.
when you say "doesn't have a name", i assume you mean you don't have a variable to hold the reference to the object. So create a variable to hold the reference.
This post was edited by carteblanche on Apr 28 2014 10:44pm