有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

swing Java错误找不到符号

我不明白为什么在几个地方出现“错误找不到符号”。谁能解释一下这个简单的问题吗

  • 价格计算器。java:18:错误:找不到符号---私有JTextFeild priceFeild1
  • 价格计算器。java:19:错误:找不到符号---私有JTextFeild priceFeild2
  • 价格计算器。java:41:错误:找不到符号--SetDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
  • 价格计算器。java:44:错误:找不到符号--buildPanel()

    import javax.swing.*;
    public class PriceCalculator extends JFrame
    {
    private JPanel panel;                               // References the panel
    
    private JLabel messageLabel1;                       // References the whole sale label
    private JLabel messageLabel2;                       // References the markup label percentage
    
    private JTextFeild priceFeild1;                 // References the whole sale price
    private JTextFeild priceFeild2;                 // Referencts the markup label percentage
    
    private JButton calcButton;                     // References the calculator button
    
    private final int WINDOW_WIDTH = 550;           // References the window width
    private final int WINDOW_HEIGHT = 550;          // Referenecs the window height
    
    /** 
    
    Constructor below
    
    */
    
    public PriceCalculator()
    {
    // Set the window title
    setTitle("Retail Price Calculator");
    
    // Set the size of the window
    setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    
    // Set the [x] exit button to close the program for the user
    setDefaultCloseOpperation(JFrame.EXIT_ON_CLOSE);
    
    // Build the panel and add it to the JFrame
    buildPanel();
    
    // Add the contents to the panels frame
    add(panel);
    
    // Display the window here
    setVisible(true);
    }
    
    
    
    
    /**
    
    Main Method Below
    
    */
    
    public static void main(String[] args)
    {
    new PriceCalculator();
    }
    
    }
    

共 (2) 个答案

  1. # 1 楼答案

    这是因为你拼写错了。应该是JTextField

    而且,setDefaultCloseOperation而不是setDefaultCloseOpperation

  2. # 2 楼答案

    你的拼写错误:

    JTextFeild而不是JTextField

    setDefaultCloseOpperation(JFrame.EXIT_ON_CLOSE);Operation中使用了2p,而不是setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);