Since I'm still new to Java, I'm running into some need for clarification how imports should be done properly.
First:
import java.awt.*;
import java.swing.*;
I'm assuming the * means anything under the "awt" and "swing" directory. But I've seen people doing this before:
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import javax.swing.*;
Am I misunderstanding something? Or am I simply finding redundancy?
import javax.awt.*
Will include all of the classes in the package javax.awt
however it will not inclue any other packages nested inside of javax.awt
such as javax.awt.event
. You need to use that as a separate import. All packages of different names needed to be included separately.
Using import javax.swing.*
you will not need the following imports:
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
because they are direct children of the swing
package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With