Is it possible to use all the components of Swing class such as JFrame without extending an existing class to JFrame? if so why then programmers usually extend their classes to JFrame class and import swing at the same time?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Is it possible to use all the components of Swing class such as JFrame without extending an existing class to JFrame? if so why then programmers usually extend their classes to JFrame class and import swing at the same time?
JFrame is one class in the javax.swing package.
Extending a class has nothing to do with what import statements you code.
An import statement is used by the compiler to find the definition of a class that is defined in a package.
If you don't understand my answer, don't ignore it, ask a question.
Well, can I use JFrame simply by importing all of the swing classes without extending an existing class to JFrame? I am sorry if my question doesn't make sense but I am a newbie in java programming and in a tutorial few days back I saw someone making a JFrame only by importing all of the swing classes and he didn't extend the existing class to JFrame.
If you do that then this would fail:
public JFrame jf = new ClassThatDoesNotExtendJFrame();//fail
You do not need to use the import statement to use any of the java classes. You can code the full package/class name:The import statement tells the compiler where to look to find class definitions. It's sort of an extension of classpath. The import statement does not create any code in a program.public MyFrame extends javax.swing.JFrame { ...}
If you don't understand my answer, don't ignore it, ask a question.
using import statements is just a shortcut. At any time you can use fully qualified name of classes or interfaces.