错误找不到符号

时间:2013-02-22 23:00:33

标签: java user-interface

我收到了这个错误 ./CreatePanel.java:35:错误:找不到符号     redText = new Jlabel();                 ^   符号:Jlabel类   location:类CreatePanel 我该如何解决这个问题?

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

public class CreatePanel extends JPanel
 {
   private Vector petList; 
   private JButton button1;
   private SelectPanel sPanel;
   private JLabel text1;
   private Jlabel redText;
   private JTextField petInput;
   private JTextArea petsIn;
   private Panel wPanel;
   private Panel alertPanel;
   private Panel petPanel;
   private Panel createPanel;



 public CreatePanel(Vector petList, SelectPanel sPanel)
  {
    this.petList = petList;
    this.sPanel = sPanel;


    // orgranize components here
    // here is an example
    text1=new JLabel("Enter a Pet Type"); 

    redText=new Jlabel();

    petInput=new JTextField();

    button1=new JButton("Create a Pet");

    petsIn=new JTextArea("No Pet");

    wPanel=new Panel(); 

    petPanel=new Panel();  

    createPanel=new Panel(); 

    alertPanel=new Panel();

    alertPanel.setLayout(new GridLayout(1,2));

    createPanel.setLayout(new GridLayout(2,3));

    petPanel.setLayout(new GridLayout(1,2));

    wPanel.setLayout(new GridLayout(3,1));  

    button1.addActionListener(new ButtonListener());

    add(wPanel);

    wPanel.add(alertPanel);

    alertPanel.add(redText);

    wPanel.add(petPanel);

    petPanel.add(text1);

    petPanel.add(petInput);

    wPanel.add(createPanel);

    createPanel.add(new JLabel());

    createPanel.add(button1);

    createPanel.add(new JLabel());  

    createPanel.add(new JLabel());  

    createPanel.add(new JLabel());

    createPanel.add(new JLabel());

    add(petsIn);

  }

  private class ButtonListener implements ActionListener
   {
    public void actionPerformed(ActionEvent event)
     {
         //when the button is pushed, the pet type
         //should be added to the list. This is also where
         //errors are handled.
         String inputPet = petInput.getText(); 

         boolean checker = false; 

         for (int p = 0; p < petList.size(); p++){ 
             if (inputPet.equalsIgnoreCase((String) petList.get(p))){
                checker = true; 

                 break;
             }
         }


         if(inputPet.equals("")){
             redText.setText("Please enter a pet type.");

             redText.setForeground(Color.red);
         } 
         else if (checker == true){
             redText.setText("The pet type already exists.");

             redText.setForeground(Color.red);
         }
          else {
             petList.add(inputPet);

             String addedPets = (String) petList.get(0);

             for(int i = 1; i < petList.size(); i++){
                 addedPets += "\n" + (String) petList.get(i);
             }
             redText.setText("Pet type added.");
             redText.setForeground(Color.red);
             petsIn.setText(addedPets);
             sPanel.updateUI();             
          } 
     } //end of actionPerformed method
         redText.setText("");

  } //end of ButtonListener class

} //end of CreatePanel class

我收到了这个错误 ./CreatePanel.java:35:错误:找不到符号     redText = new Jlabel();                 ^   符号:Jlabel类   location:类CreatePanel 我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

看起来你的redText的JLabel声明是“Jlabel”,应该是“JLabel”。需要一个大写的L。