tags:

views:

1142

answers:

2
import java.awt.*;
import javax.swing.*;
public class 
import javax.swing.*;
import java.awt.*;
import javax.swing.tree.*;
import javax.swing.event.*;
/*<applet code="JT.class" width=200 height=300>
</applet>*/

 

public class JT extends JApplet {
    JTree tree;
    JTextField box;
    Object nodeInfo;
    String node1;
    public void init() {
        Container c=getContentPane();
        c.setLayout(new BorderLayout());
        DefaultMutableTreeNode topNode=new DefaultMutableTreeNode("qiscet");
        DefaultMutableTreeNode cou=new DefaultMutableTreeNode("Courses");
        DefaultMutableTreeNode mca=new DefaultMutableTreeNode("MCA");
        DefaultMutableTreeNode mba=new DefaultMutableTreeNode("MBA");
        DefaultMutableTreeNode tech=new DefaultMutableTreeNode("B.tech");
        topNode.add(cou);
        cou.add(mca);   
        cou.add(mba);
        cou.add(tech);
        DefaultMutableTreeNode manage=new DefaultMutableTreeNode("Management");
        DefaultMutableTreeNode ac=new DefaultMutableTreeNode("Accounts");
        DefaultMutableTreeNode sp=new DefaultMutableTreeNode("Sports");
        DefaultMutableTreeNode lib=new DefaultMutableTreeNode("Library");
        topNode.add(manage);
        manage.add(ac); 
        manage.add(sp);
        manage.add(lib);
        tree=new JTree(topNode);
        c.add(tree,BorderLayout.NORTH);
        box=new JTextField("",80);
        c.add(box,BorderLayout.SOUTH);
    }
}

My question is without using "Container c=getContentPane();" i am getting correct output .How it is possible?What is the reason for this?

+7  A: 

To begin with Swing made you use getContentPane() for things like add() and setLayout() to make you realize that there were different layers. After a while I guess they conceded that it was a pain so they had the getContentPane() called internally so you didn't have to anymore.

This was changed in JDK 1.5:

Lastly, after seven years, we've made jFrame.add equivalent to jFrame.getContentPane().add()

And here is a link to the rationale behind the original reason.

TofuBeer
A: 

Q. When we are writing a line in text area and giving space between the words then we want read last word and compare with dictonary. how this is possible like when i was writing in this text area the word dictonary it shows this is wrong word. kindly give me example for the same thanks

Hint: If your answer starts with "Q.", it's probably not an answer.
Michael Myers