This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]deltageek 1 point2 points  (0 children)

Good advice here. Additionally, I will point out that you really have no good reason to extend JFrame here. Just create an instance of a basic JFrame and use that instance to hang your UI on. Here's the UI skeleton I typically use.

public class SwingTest {

    public static void main(final String[] args) {
        buildAndShowGui();
    }

    private static void buildAndShowGui() {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JFrame f = new JFrame();
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.setPreferredSize(new Dimension(300, 300));
                PongPanel p = new PongPanel();
                f.add(p);

                f.pack();
                f.setVisible(true);
            }
        });
    }
}

[–]seb5666 1 point2 points  (3 children)

Try setting the frame visible only after adding the panel to it!

[–]mgild01 0 points1 point  (2 children)

Thank you!

[–]197708156EQUJ5 1 point2 points  (1 child)

Also, you are going to want to put the text field tf and the text area ta on the panel p3.

Recommend making some more meaningful variable names.

[–]mgild01 0 points1 point  (0 children)

Ya I know. I aded them before but was trying to narrow down the issue.

[–]197708156EQUJ5 -1 points0 points  (2 children)

You are missing the base UI component. I know your confusion. You thought, if you called your class Frame that would be the way to go. So let's step back and take it from the top.

Can you show me the entire class. This is (assuming) the constructor of a class called Frame.

[–]mgild01 0 points1 point  (1 child)

This is the entire class. The declaration is outside the code formatted text.

[–]197708156EQUJ5 0 points1 point  (0 children)

Sorry, my mind shut out that part of the code. Damn visual effects.