Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

component specific listeners don't work !

Status
Not open for further replies.

StanSteve

Instructor
Sep 22, 2001
16
US

Dear Java Friend,
I am attempting to define small classes to be separate component specific listeners. But this short program has two error messages.

"illegal start of expression"
public void actionPerformed(ActionEvent ae)

and "malformed expression"
ActionListener al = new ActionListener();

your advice is appreciated.
Stan:)
dominskis@aol.com


 
firstly.

it may not be that particular line that is in error, or it may be related to something you have missed out further on. You need to provide more detail.

secondly, as far as I am aware ActionListener is an interface and so cannot be directly instaiated on the heap as you are attempting to do. You must instead make the class in question implement the interface e.g.

class MyClass implements ActionListener

 
if you want to add an actionlistener directly to an individual component - try using an anonymous inner class.

the action listener can also be implemented by the class containing the component (and adding "this" when you add the actionlistener to the component) or by a completely seprate class that must implement either the actionlistener ointerface or the action adapter class.

I hope you are not a Java instructor.
 

Thank you PipK ! ,
I will try
MyClass implements ActionListener
:)
Stan
[/b[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top