Click here to Skip to main content
15,886,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone!

I'm new to java and java swing.

I'm learning java language and swing at the same time.

I have some code with JFrame like this:
Java
import javax.swing.JFrame;
import javax.swing.JLabel;

public class mainFrame extends JFrame {
	private JLabel lb1;
	public mainFrame()
	{
		super("Title");
		setVisible(true);
		setSize(200, 150);	
		lb1 = new JLabel();
		lb1.setText("Hello world!");
		add(lb1);
	}
	public static void main(String args[])
	{
		mainFrame frm1 = new mainFrame();
	
	}	
}


The point is:
1. what is the meaning of using super(). Is that true if super() is used only in constructors?
2. Calling method setVisible(true) or setSize(200, 150) and add(lb1) without an instance (object) sounds very strange to me? I thought I must have been like someObject.setVisible()???

I think my explanation is clear enough!

Any help or suggesstion would be greatly appreciated!
Posted

1. Calling super in the constructor calls the constructor of the base class, in this case JFrame.
2. If a method is called from within a class, the instance is implicitly this and (that is the instance of the object you're currently in). Unless otherwise specified.

Hope this helps,
Fredrik Bornander
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Mar-12 21:13pm    
Sure, a 5.
--SA
@Fredrik Bornander

Yes, it really helped me. How do I accept a solution and mark it as solved question?

Oh man this topic is already marked as solved!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900