Why this method does not use any properties of the object?

Posted by Roman on Stack Overflow See other posts from Stack Overflow or by Roman
Published on 2010-03-12T10:51:56Z Indexed on 2010/03/12 10:57 UTC
Read the original article Hit count: 339

Filed under:
|
|
|

Here I found this code:

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


public class FunWithPanels extends JFrame {

    public static void main(String[] args) {
        FunWithPanels frame = new FunWithPanels();
        frame.doSomething();
    }

    void doSomething() {
        Container c = getContentPane();

        JPanel p1 = new JPanel();
        p1.setLayout(new BorderLayout());
        p1.add(new JButton("A"), BorderLayout.NORTH);
        p1.add(new JButton("B"), BorderLayout.WEST);

        JPanel p2 = new JPanel();
        p2.setLayout(new GridLayout(3, 2));
        p2.add(new JButton("F"));
        p2.add(new JButton("G"));
        p2.add(new JButton("H"));
        p2.add(new JButton("I"));
        p2.add(new JButton("J"));
        p2.add(new JButton("K"));

        JPanel p3 = new JPanel();
        p3.setLayout(new BoxLayout(p3, BoxLayout.Y_AXIS));
        p3.add(new JButton("L"));
        p3.add(new JButton("M"));
        p3.add(new JButton("N"));
        p3.add(new JButton("O"));
        p3.add(new JButton("P"));

        c.setLayout(new BorderLayout());
        c.add(p1, BorderLayout.CENTER);
        c.add(p2, BorderLayout.SOUTH);
        c.add(p3, BorderLayout.EAST);

        pack();
        setVisible(true);
    }
}

I do not understand how "doSomething" use the fact that "frame" is an instance of the class JFrame. It is not clear to me because there is no reference to "this" in the code for the method "doSomething".

© Stack Overflow or respective owner

Related posts about java

Related posts about oop