• 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

Clarification --> Import statement

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is both of these statements required to run any program having event handling in swing ?
import java.awt.*;
import java.awt.event.*;
or
import java.awt.*; is alone will do ? Why?
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only if the Swing program uses any classes out of AWT, or any AWT event classes (which it most probably will... ).

When you import java.awt.*, you import all the classes in the java.awt package, but no sub-packages of java.awt (such as java.awt.event). You have to import each package separately. As for why? I guess that's just how James Gosling wanted to work imports when he made the Java language specification. (Actually, though, it's a good thing to specifically import packages and not have them load subpackages. You have no idea how deep the subpackages go... think what would happen if you said "import java.*" in this situation! )

In your case, if you only need access to the AWT events in your class, you can just import java.awt.event, you don't have to import java.awt.
[ December 26, 2002: Message edited by: Nathan Pruett ]
 
Adinarayana Pabolu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the information
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic