简体   繁体   English

BoxLayout:编译错误

[英]BoxLayout: Compilation Errors

I'm trying to make a BoxLayout layout in my program. 我正在尝试在程序中制作BoxLayout布局。 I use Eclipse, so when I entered these lines, 我使用Eclipse,所以当我输入这些行时,

JTextArea fntxt = new JTextArea(1, 20);
JTextArea lntxt = new JTextArea(1, 20);
JButton back4 = new JButton("Back");
JButton sub2 = new JButton("Submit");
JLabel cal = new JLabel("Create new Account");
JPanel cac = new JPanel();
//Error line:
cac.setLayout(new BoxLayout(cac, BoxLayout.PAGE_AXIS));

//In Constructor
    cal.setFont(new Font("Times New Roman", Font.PLAIN, 24));
    cac.add(cal);
    cac.add(new JLabel("First Name:"));
    cac.add(fntxt);
    cac.add(new JLabel("Last Name"));
    cac.add(lntxt);
    cac.add(back4);
    cac.add(sub2);

it showed these errors in the error line: 它在错误行中显示了这些错误:

- Syntax error on token ".", @ expected after this token
- Syntax error, insert "Identifier (" to complete 
 MethodHeaderName
- Syntax error, insert ")" to complete MethodDeclaration
- Syntax error, insert "SimpleName" to complete 
 QualifiedName

and when I try to run it, this comes up in the console: 当我尝试运行它时,它会出现在控制台中:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

at Create.main(Create.java:125)

The 125 line is the main method declaration line. 125行是主方法声明行。 I can't understand what is the error and what to do to debug it. 我不明白这是什么错误以及如何调试它。

There is an extra closing bracket, also this line has to be inside a method or constructor: 还有一个额外的结束括号,该行也必须位于方法或构造函数内部:

inside constructor 内部构造函数

cac.setLayout(new BoxLayout(cac, BoxLayout.PAGE_AXIS)));
                                     remove this------^

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

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