• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question on ActionListener

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i've no idea
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic