简体   繁体   English

Java swing border错误

[英]Java swing border error

I am adding a java swing border into my existing code. 我在现有代码中添加了一个java swing边框。 I have referred online and put in my code which I got from a site, but on running it I get an error, and when highlighting in my intellij this pops up : cannot resolve symbol 'p'. 我已经在网上推荐并输入我从网站上获得的代码,但在运行它时我得到一个错误,当我在intellij中突出显示时弹出:无法解析符号'p'。 Where am I going wrong ? 我哪里错了?

private class AnotherBorderTest extends JFrame {
    public AnotherBorderTest() {
        setTitle("Border Test");
        setSize(450, 450);

        JPanel content = (JPanel) getContentPane();
        content.setLayout(new GridLayout(6, 2, 3, 3));


        p = new JPanel();
        p.setBorder(new MatteBorder(new ImageIcon("BALL.GIF")));
        p.add(new JLabel("MatteBorder"));
        content.add(p);

        setVisible(true);
    }

    public void main(String args[]) {
        new AnotherBorderTest();
    }
}

In your code you didn't have any value assigned to variable p . 在您的代码中,您没有为变量p分配任何值。 Use code 使用代码

JPanel p = new JPanel(); /* instead of p = new JPanel() alone */

as it declares and assigns the variable p of type JPanel with a value of object new JPanel() . 因为它声明并为 JPanel类型的变量p赋值为object new JPanel()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM