-2

i'm learning Java for one year now and this question is confusing me.

At the moment i'm working with Java Swing and i want to know why i have to write the line

import java.awt.event.*;

when i want to use the actionListener even when i've already imported the whole awt package before :/

import java.awt.*

why do i have to tell the compiler to import a Sub-package (is it the right name?), for instance the event package, when i already imported everything under the awt package?

Thanks alot!

Murad Alm.
  • 79
  • 9
  • Because java.awt and java.awt.event are two different packages. import java.awt.* imports classes from the java.awt package. Not from java.awt.event. Google for "java tutorial import", click on the first link: https://docs.oracle.com/javase/tutorial/java/package/usepkgs.html. And surprisingly enough, it has the answer you're looking for. – JB Nizet Jul 29 '18 at 09:32

1 Answers1

0

Because each package is separate. They don't have a parent-sub relationship.

import java.awt;

doesn't mean that java.awt.event is imported.

EmOwen
  • 104
  • 6