Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question on ActionListener  RSS feed

 
Clay Adkerson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im trying to add ActionListener to some buttons in my applet. When i compiled it gave me this error:
C:\JavaStuff\Flier.java:7: cannot resolve symbol
symbol : class ActionListener
location: class Flier
public class Flier extends Applet implements ActionListener
^
I implemented it with this

I imported java.awt.*; so it should get it. Im using J2sdk1.4.2. I made sure everything is all in the right case too. Do i have to make a separate class for the ActionListener? Anyone know? Thanks ahead, I'll check this in the morning.
-Clay
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you import java.awt.event.* in addition to java.awt.* ?
 
Clay Adkerson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out in class today. I though that import java.awt.*; would import it but i added import java.awt.event.*; and got another error which i fixed by adding the ActionPerformed method and no errors. Thanks for the help though.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For clarification the .* syntax imports all the classes from that package. It does not recursively import any classes from subpackages.

Layne
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, Java doesn't have the concept of package hierarchies at all. The dot (.) is just part of Suns naming convention and doesn't carry any semantic.
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW what's your opinion: is it better to import each needed class or instead import all (.*)?
thanks in advance
[ March 18, 2005: Message edited by: miguel lisboa ]
 
Svend Rost
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW what's your opinion: is it better to import each needed class or instead import all (.*)?


In general you ought to specify which classes you import.

If you specify which classes you import, it's easier for others to
understand what's happening in your class.

/Svend Rost
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, thank you; because eclipse imports every clas, while (some) agile people recomend one uses *. because, they say, removes duplication
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by miguel lisboa:
BTW what's your opinion: is it better to import each needed class or instead import all (.*)?
thanks in advance

[ March 18, 2005: Message edited by: miguel lisboa ]

I've seen many recommendations that you should import each class. For one, this helps avoid ambiguity if two packages contain two different classes with the same name. I know that NetBeans 3.6 has a setting that sets a threshold for the number of classes from a given syntax before importing the whole package. I typically set this to a very high number (9999) so that individual classes are imported. Perhaps Eclipse has a similar setting?

Layne
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i've no idea
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by miguel lisboa:
i've no idea


Me neither, but that's what the Help files are for!
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
eclipse has a context menu from where you can tell it to organize imports: even if you previously had used *. it will replace that with all needed classes
 
Nigel Browne
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by miguel lisboa:
eclipse has a context menu from where you can tell it to organize imports: even if you previously had used *. it will replace that with all needed classes

It is easier to set by going Window>preferences>java>code style>Organize imports then set the number of imports needed for .* in the text field.
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the longer i'm at java the more i get convinced one allways has to go all the way through
i read this in help:
You can also choose Organize Imports from the context menu of the import declarations in the Outline view.
Note: You can specify the order of the import declarations in preferences Window > Preferences > Java > Code Style > Organize Imports.


but as i didnt actually check that path i was unware of the possibility you just refered

thanks for making that good point
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!