2013-02-22 138 views
-1

我得到这个错误 ./CreatePanel.java:35:错误:找不到符号 redText = new Jlabel(); ^ 符号:Jlabel类 位置:class 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 =新的JLabel(); ^ 符号:Jlabel类 位置:class CreatePanel 我该如何解决这个问题?

回答

2

看起来像JLabel的红色文本声明是“Jlabel”,当它应该是“JLabel”。需要大写字母L.

+0

我现在正在收到此错误./CreatePanel.java:139:错误:预计 redText.setText(“”); ^ ./CreatePanel.java:139:error:非法启动类型 redText.setText(“”); ^ ./CreatePanel.java:139:error:package redText does not exist redText.setText(“”); ^ – user2101126 2013-02-22 23:34:47

+0

我相信“} // end of actionPerformed方法redText.setText(”“);”是你的罪魁祸首它超出了你的actionPerformed方法。我猜你可能不想要额外的“redText.setText(”“);”所以删除它是安全的。 – 2013-02-22 23:54:49