Results 1 to 4 of 4
- 02-13-2011, 01:54 PM #1
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
Quick question about import and inheretence
Hi,
I have two classes, the first is with my main() function and it has this:
I have bolded the part that I want to talk about, and my second class has this:import javax.swing.JFrame;
public class GUI {
My question:import java.awt.FlowLayout; // gets the flowlayout
import javax.swing.JFrame; // gets the whole pane with the minimize,maximize, x button etc
import javax.swing.JLabel;
public class GUI_Sub extends JFrame{
How come in the main class I have to import like this "javax.swing.JFrame" but in the second class (which does not have a main() method and gets called by the first class) all I say is " extends JFrame" and thats enough?
Shouldnt it be "extends javax.swing.JFrame"?
How does Java know which "JFrame" I am talking about?
Thanks!Last edited by N00Bie; 02-13-2011 at 01:57 PM.
- 02-13-2011, 02:37 PM #2
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
I think you've missed that you also has an import for javax.swing.JFrame in your second class. So it knows you mean javax.swing.JFrame for the extend. If you were to remove that import, you'd have to specify the complete path to JFrame in the extends line.
Java Code:import java.awt.FlowLayout; // gets the flowlayout [B]// (removed) import javax.swing.JFrame;[/B] // gets the whole pane with the minimize,maximize, x button etc import javax.swing.JLabel; public class GUI_Sub extends [B]javax.swing.JFrame[/B]{
- 02-13-2011, 06:19 PM #3
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
Ah! That makes sense! Thanks!
(Also like your sig... so true... so damn true!)
- 02-13-2011, 06:37 PM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Similar Threads
-
Quick question
By Thumper in forum New To JavaReplies: 10Last Post: 11-07-2010, 10:06 PM -
Really quick question
By shadycharacter in forum New To JavaReplies: 2Last Post: 04-22-2010, 10:06 PM -
One last quick question
By jigglywiggly in forum New To JavaReplies: 7Last Post: 01-26-2009, 08:53 AM -
Quick Question
By Graeme in forum New To JavaReplies: 4Last Post: 01-08-2009, 08:01 PM -
Quick Question
By Spenc in forum New To JavaReplies: 3Last Post: 09-22-2008, 02:26 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks