Why when importing the java.awt or javax.swing and we want to use the event, why should we import the event alone, and not incuded when we import all of java.awt or javax.swing?

03-27-2011, 11:14 AM

JosAH

Quote:

Originally Posted by aizen92

Why when importing the java.awt or javax.swing and we want to use the event, why should we import the event alone, and not incuded when we import all of java.awt or javax.swing?

If you import a sub-package x.y you are not importing the package x (nor vice versa); a.a.m.o.f. subpackages have nothing to do with their 'parent' packages.

kind regards,

Jos

03-27-2011, 11:20 AM

sunde887

I don't have a great understanding of the topic, but I found jos's statement confusing, here is my attempted explanation, which can be checked by looking at the arc. Others will also tell me if I am wrong.

The javax.swing package called on import has a bunch of java source files and subdirectories. The import javax.swing.* imports all of the src files in that folder, but not it's subdirectories. javax.swing has a subdirectory called event.

I hope this is correct. Others will call me out if I am giving bad information.

03-27-2011, 11:24 AM

aizen92

lol Jos sorry but i got somehow confused
@sundae i got what you said, and if this is correct then i understood it

03-27-2011, 11:27 AM

sunde887

You can confirm it by checking the src files which should be located in something like

Code:

c:/program files/java/jdk/src

Go there and navigate your way to java.awt and see what files are in there and if there is an event sub directory in there.

03-27-2011, 11:41 AM

aizen92

actually yeh, it was true, i entered the src file, and in the javax there were the normal classes we use whem importing javax.swing.*, and there was a folder for event
so i think sundae's explaination is true

03-27-2011, 11:44 AM

JosAH

Quote:

Originally Posted by sunde887

I don't have a great understanding of the topic, but I found jos's statement confusing

All I was saying is that if you import something from a sub-package x.y.* you are not importing anything from the package x.*; the same holds the other way around, i.e. if you import classes from x.* you are not importing anything from x.y.*; in other words, those two packages are completely unrelated when it comes to importing stuff from them.