Can someone please explain to me the use of super(t) in the following code. Thanks alot.

import javax.swing.*;
import java.awt.*;

public class ComponentExample(String t){

super(t);
Container cp = getContentPane();

cp.add(new JButton("Click", "North");
pack();

}

10-13-2004, 08:03 PM

Kram

Java works in a heirarchy manner, each class is either a parent or a child of another class, but in the end they all come back to the Object class.

So when you say super(t) you are calling the constructor of the class that your class is a child of, so in your case you are calling the Object constructor and passing it the String t, not too exciting, not even necessary...

10-13-2004, 08:08 PM

scracker

How come when the string t is passed, its gonna become the title of the window created? I dont get the relationship between how that works and the fact that it passes the String to the Object constructor. Can you please explain further? Thanks a lot.

10-13-2004, 09:06 PM

Kram

The constructor of the super clas that you are passing the value must set it up as on of the parameters for your window.

Its simply one of the operations of the constructor of the super class. Keeping in mind that your class has derived "from" the Object class, so its like your classes parent, and that is the relationship.

If you have a class that "Extends" JApplet for example, then the JApplet class will be the super/parent class.

10-14-2004, 08:11 AM

mikeBarr81

As it is, the code above is invalid. You seem to have grouped together the class definition and the constructor all into one thing. Maybe it should look something like this?[code]import javax.swing.*;
import java.awt.*;