Campbell Ritchie wrote:
Don’t do that. There are something like 4500 classes in the standard Oracle/Sun Java API, so unless you expect to learn them all off by heart, that will be a useless task. What you need to know is how to find those classes in the API. Look here, and you will see it is saysDe Huaste wrote: . . . I'll research and commit to memory those which are "core" and those that are swing only. . . .
So now you know to import it in the package java.awt.event. You ought to bookmark the index to the API documentation because you will use it all the time.java.awt.event
Interface ActionListener
If you import something you don’t use, 99% of the time this is what will happen: Nothing.
You can occasionally have problems. Try importing java.util.* and javax.swing.* and using the Timer class
When you have worked out what went wrong, you will find out why many people prefer to import individual classes rather than on‑demand imports. More about imports here.
I would have known you had the wrong import, too, had you said it was a compiler error. But you didn’t, so I looked at your code wondering what the logic error was and couldn’t find it.
Rob Spoor wrote:I didn't say you had to remove the javax.swing.event import. I must admit it's a bit confusing, with some event listeners being in java.awt.event and others in javax.swing.event. The distinction is that those in java.awt.event are the "core" event listeners that are also used by AWT, and those in javax.swing.event are for Swing only.
Rob Spoor wrote:ActionListener and ActionEvent are in package java.awt.event, not javax.swing.event.
Campbell Ritchie wrote:And what goes wrong when you try it?
Jeff Verdegan wrote:
De Huaste wrote:
Aj Prieto wrote:Instead of
Try
Also, please use code tags when posting code
Thank you very much. And will do
Much more important than solving this particular issue is the question: Do you understand the difference, and why one does what you want but not the other?
Aj Prieto wrote:Instead of
Try
Also, please use code tags when posting code