我正在尝试在我的程序中制作BoxLayout布局。我使用 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);
它在错误行中显示了这些错误:
- 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
当我尝试运行它时,这出现在控制台中:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at Create.main(Create.java:125)
125行是主要方法声明行。我不明白错误是什么以及如何调试它。
还有一个额外的右括号,这一行也必须在方法或构造函数内:
内部构造函数
cac.setLayout(new BoxLayout(cac, BoxLayout.PAGE_AXIS)));
remove this------^