Link to home
Start Free TrialLog in
Avatar of pigmentarts
pigmentartsFlag for United Kingdom of Great Britain and Northern Ireland

asked on

why is the actionEvent greyed out

bnStart.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                doStart();                                           ^
                                                                           ^  this is greyed out, does that eman i'm not using it?
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
bnStart.setEnabled(true);
greyed out? Where? In your editor?
That would depend on your IDE. If it compiles, yes, possibly. If it doesn't, maybe it's not imported
What editor/IDE do you use?
>> If it doesn't, maybe it's not imported

If new ActionListener () complies (means it is imported), then so should ActionEvent.... are you using Netbeans?
>>If new ActionListener () complies (means it is imported), then so should ActionEvent

Why so?
mayank probably means that if you have

import java.awt.event.*;  

both ActionListener and ActionEvent are known

But mayank, you could of course have

import java.awt.event.ActionListener;
Because they are in the same package? Unless he imported java.awt.event.ActionListener instead of event.* .... :)

Anyway, most IDEs still recognize the classes and show a colour regardless of whether it was imported or not (of course, on compiling you would know the error).... ;)
>>Unless he imported java.awt.event.ActionListener instead of event.* .... :)

Most decent IDEs will encourage precisely that good practice ( as opposed to import x.* )  ;-)
CEHJ, I'm interested in the reason why it would be good/better practice to have

import java.awt.event.ActionListener;

instead of

import java.awt.event.*;
Because it announces precisely what classes are being used (unless a declaration is redundant [a good ide will warn about that too]) which is useful for maintenance
Mmmm. That's the argument I always hear.
But so far, I don't experience any (maintenance)problems with using *
Good point. Personally, I use import java.awt.event.* to reduce the number of import-lines (for some reason, if there are many import lines, it doesn't look good to me and I get anxious to see where the real code of the class starts ;-)). If there are any classes with the same name and in multiple packages (like java.util.Date and java.sql.Date), then I use the full package-name in the code. Luckily - my company's coding-standard does not have a problem with that and does not enforce me to use import java.awt.event.ActionListener instead of * (phew~!) :-)

Does it have any advantage on the compile-time though?
I feel excatly like you mayank.

>> Does it have any advantage on the compile-time though?
No afaik.
Avatar of pigmentarts

ASKER

I'm back, thx for all your comments.

The only reason I've been using import java.awt.event.ActionListener instead of * is to help in the initial learning.
Just to help me build up the method of using java.
>>bnStart.setEnabled(true);

do I need to do this for the action to work? I don't think i do so whats it for?
Any questions left?
>> whats it for?
Forget that. I first thought you meant that the button the action was linked to was greyed out.
> do I need to do this for the action to work? I don't think i do so whats it for?

no
>>sounds like a reasonable assumption

but surley i am using it if the start button works d8-)