gpt4 book ai didi

java - 您对 JLabel 类做了什么?它说, "JLabel not a statement"表示错误

转载 作者:行者123 更新时间:2023-12-01 19:28:50 25 4
gpt4 key购买 nike

到目前为止,除了讨厌的 JLabel 类之外,其他一切似乎都工作正常。你们建议我改变什么以使这个程序正常工作,因为我似乎无法理解这个问题。顺便说一句,编程项目是:修改layoutdemo 程序的intropanel 类,使其使用框布局管理器。使用不可见组件在面板上两个标签之前和之间留出空间。

import java.awt.*;
import javax.swing.*;

@SuppressWarnings("serial")
public class IntroPanel extends JPanel
{
// ------------------------------------------------------------------------------
------------
// Sets up this panel with two labels
// ------------------------------------------------------------------------------
------------
public IntroPanel()
{
setBackground(Color.green);

JLabel 11 = new JLabel("Box Layout Manager Demonstration");
JLabel 12 = new JLabel("This is an example of a box layout manager.");

Component asinineProgramContainer1 = new JLabel("");
Component asinineProgramContainer2 = new JLabel("");

asinineProgramContainer1.setVisible(false);
asinineProgramContainer2.setVisible(false);

Box mainVerticleBox = Box.createVerticalBox();
Box labelBox = Box.createHorizontalBox();
Box invisibleContentBoxTop = Box.createHorizontalBox();
Box invisibleContentBoxBottom = Box.createHorizontalBox();

invisibleContentBoxTop.add(asinineProgramContainer1);
labelBox.add(11);
labelBox.add(Box.createRigidArea(new Dimension(100,100)));
labelBox.add(12);
invisibleContentBoxBottom.add(asinineProgramContainer2);

mainVerticalBox.add(invisibleContentBoxTop);
mainVerticalBox.add(Box.createGlue());
mainVerticalBox.add(labelBox);
mainVerticalBox.add(Box.createGlue);
mainVerticalBox.add(invisibleContentBoxBottom);

add(mainVerticalBox);
}
}

最佳答案

这与 JLabel 类无关。这是关于变量名称的。 java中变量名不能以数字开头。这就是您的代码失败的原因。

来源:

编辑:

并在重用变量时明确检查您所写的变量名称是否正确。

关于java - 您对 JLabel 类做了什么?它说, "JLabel not a statement"表示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60429297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com