JFrame构建面板无法正常工作

时间:2018-01-31 05:05:49

标签: 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;
     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();
    }
}

1 个答案:

答案 0 :(得分:2)

看到源代码,错误拼写'构建'作为' bulid'在两个注释和一个方法名称。更正方法名称中的拼写应解决问题,但更改所有三个实例。