我不知道在哪里可以找到这个代码中错误的来源,希望有人能帮忙。本质上,这一小部分是我的一个更大的项目的一部分,创建一个计算器的图形用户界面。
JPanel box=new JPanel();
box.setPreferredSize(new Dimension(600,300));
BoxLayout b=new BoxLayout(box, BoxLayout.X_AXIS);
box.setLayout(b);
box.add(graphOutline);
box.add(checks);
box.add(checkd);
box.add(check2d);
box.add(radBut);
box.add(yEquals);
box.add(y); //}} //}}
//{{Bottom Buttons //{{ basicbuttons JPanel, includes all the numbers and decimal
JPanel basicbuttons=new JPanel();
GridBagLayout gbl=new GridBagLayout();
GridBagConstraints c=new GridBagConstraints();
basicbuttons.setLayout(gbl);
c.fill=GridBagConstraints.BOTH; //{{button 1
JButton one = new JButton("1");
one.setPreferredSize(new Dimension(60,40));
c.gridx=0;
c.gridy=2;
gbl.setConstraints(one, c);
basicbuttons.add(one); //}} //{{button 2
JButton two = new JButton("2");
two.setPreferredSize(new Dimension(60,40));
c.gridx=1;
c.gridy=2;
gbl.setConstraints(two, c);
basicbuttons.add(two); //}} //{{button 3
JButton three = new JButton("3");
three.setPreferredSize(new Dimension(60,40));
c.gridx=2;
c.gridy=2;
gbl.setConstraints(three, c);
basicbuttons.add(three); //}} //{{button 4
JButton four = new JButton("4");
four.setPreferredSize(new Dimension(60,40));
c.gridx=0;
c.gridy=1;
gbl.setConstraints(four, c);
basicbuttons.add(four); //}} //{{button 5
JButton five = new JButton("5");
one.setPreferredSize(new Dimension(60,40));
c.gridx=1;
c.gridy=1;
gbl.setConstraints(five, c);
basicbuttons.add(five); //}} //{{button 6
JButton six = new JButton("6");
six.setPreferredSize(new Dimension(60,40));
c.gridx=2;
c.gridy=1;
gbl.setConstraints(six, c);
basicbuttons.add(six); //}} //{{button 7
JButton seven = new JButton("7");
seven.setPreferredSize(new Dimension(60,40));
c.gridx=0; c.gridy=0;
gbl.setConstraints(seven, c);
basicbuttons.add(seven); //}} //{{button 8
JButton eight = new JButton("8");
eight.setPreferredSize(new Dimension(60,40));
c.gridx=1;
c.gridy=0;
gbl.setConstraints(eight, c);
basicbuttons.add(eight); //}} //{{button 9
JButton nine = new JButton("9");
nine.setPreferredSize(new Dimension(60,40));
c.gridx=2;
c.gridy=0;
gbl.setConstraints(nine, c);
basicbuttons.add(nine); //}} //{{button 0
然而,我不断收到错误,例如
内标识“setPreferredSize”语法错误,此内标识后应为=
以及
标记“fill”出现语法错误,此标记后面需要VariableDeclaratorId
每当我尝试使用
box.setPreferredSize(new Dimension(600,300));
以及
c.fill=GridBagConstraints.BOTH;
分别。
1条答案
按热度按时间ogq8wdun1#
问题是你显然直接在类中得到了代码。把它 Package 在方法中,它就会被编译。所有非初始化代码必须在方法中。