Java JFrame生成面板不工作
我已经尽了一切可能来纠正这个错误。每次我编译程序时,错误都会消失Java JFrame生成面板不工作,java,swing,compiler-errors,jframe,panel,Java,Swing,Compiler Errors,Jframe,Panel,我已经尽了一切可能来纠正这个错误。每次我编译程序时,错误都会消失 KiloConverter.java:25: error: cannot find symbol 如何解决此错误 import javax.swing.*; // Needed for swing classes public class KiloConverter extends JFrame { private JPanel panel; private JLabel messageLabel;
KiloConverter.java:25: error: cannot find symbol
如何解决此错误
import javax.swing.*; // Needed for swing classes
public class KiloConverter extends JFrame
{
private JPanel panel;
private JLabel messageLabel;
private JTextField kiloTextField;
private JButton calcButton;
private final int WINDOW_WIDTH = 310;
private final int WINDOW_HEIGHT = 100;
//constructor
public KiloConverter()
{
setTitle("Kilometer Converter");
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//bulid the panel and add it to the frame
buildPanel();
//Add the panel to the frame's content page
add(panel);
setVisible(true);
}
//the bulid panel method adds a label, a text field,
//and a button to a panel
private void bulidPanel()
{
//Create a label to display instructions.
messageLabel = new JLabel("Enter a distance " + "in kilometers");
//Create a text field 10 characters wide.
kiloTextField = new JTextField(10);
//create a button with the caption CALCULATE
calcButton = new JButton("Calculate");
//create a JPanel object and let the panel field reference it
panel = new JPanel();
//Add the label, text fieldm and button components to the panel
panel.add(messageLabel);
panel.add(kiloTextField);
panel.add(calcButton);
}
public static void main (String[] args)
{
new KiloConverter();
}
}
看到的源代码在两个注释和一个方法名中错误地将“build”拼写为“bulid”。更正方法名称中的拼写应该可以解决问题,但要更改所有三个实例。看到的源代码在两个注释和一个方法名称中将“build”错误地拼写为“bulid”。更正方法名称中的拼写应该可以解决问题,但要更改所有三个实例。“它需要多少详细信息”好的,编译器找不到的符号名称会很有帮助。始终复制/粘贴错误和异常输出!还要注意,显示的源代码的第25行是紧跟在
buildPanel()之后的一个空行代码>因此这似乎不准确(即:源代码在编译尝试失败后已更改)。“它需要多少详细信息”嗯,编译器找不到的符号的名称将很有帮助。始终复制/粘贴错误和异常输出!还要注意,显示的源代码的第25行是紧跟在buildPanel()之后的一个空行代码>,因此这似乎不准确(即:源代码在编译尝试失败后已更改)。