private void okJButtonactionPerformed(ActionEvent e)
 {String str="";
   Iterator pIterator=pArrayList.iterator();
   while(pIterator.hasNext())
  { Parcel current= (Parcel)pIterator.next();
    if(checkJTextField.getText().equals(current.getname()))
  str=current.getname();
 nameJTextField.setText(str);//为什么这里显示不出来啊?????????
 
 }
 

解决方案 »

  1.   

    str=current.getname();取到值了吗? 或者说,你的if判断为true吗
      

  2.   

    代码贴一下,我觉得取道值了,我不会gui 调试:(import java.awt.*;
    import java.awt.event.*;
    import java.util.*;import javax.swing.*;public class Transportation extends JFrame {
        
    private  JButton okJButton,scanJButton,addJButton,removeJButton,nextJButton,backJButton,updateJButton,editJButton;  
    private JTextField checkJTextField,idJTextField, arriveatJTextField,nameJTextField,addressJTextField,cityJTextField,zipJTextField,stateJTextField;
    private JLabel checkJLabel, arriveatJLabel,idJLabel,nameJLabel,addressJLabel,cityJLabel,zipJLabel,stateJLabel;
     private  ArrayList pArrayList=new  ArrayList ();
      int idno=0;
      int position;
      String id="";
      Parcel newParcel = null;
      Parcel current=null;
      HashMap hash=new HashMap();
      
      public Transportation() {
        createUserInterface();
      }
      // create and position GUI components
      private void createUserInterface() {
        
        Container contentPane = getContentPane();
        contentPane.setLayout(null);
         
        okJButton=new JButton();
        okJButton.setBounds(210,10,80,30);
        okJButton.setText("ok");
        contentPane.add(okJButton);
        okJButton.addActionListener(new ActionListener()
      {public void actionPerformed(ActionEvent e)
      {
         okJButtonactionPerformed( e);
      }
      }
      );
        
       
        
         
        scanJButton=new JButton();
        scanJButton.setBounds(10,300,80,30);
        scanJButton.setText(" scan");
        contentPane.add(scanJButton);
         scanJButton.addActionListener(new ActionListener()
      {public void actionPerformed(ActionEvent e)
      {
         scanJButtonactionPerformed( e);
      }
      }
      );
        
        
        addJButton=new JButton();
        addJButton.setBounds(100,300,80,30);
        addJButton.setText(" add");
        contentPane.add(addJButton);
       addJButton.addActionListener(new ActionListener()
      {public void actionPerformed(ActionEvent e)
      {
        addJButtonactionPerformed( e);
      }
      }
      );
        
        
        removeJButton=new JButton();
        removeJButton.setBounds(190,300,90,30);
        removeJButton.setText(" remove");
        
        contentPane.add(removeJButton);
      removeJButton.addActionListener(new ActionListener()
      {public void actionPerformed(ActionEvent e)
      {
        removeJButtonactionPerformed( e);
      }
      }
      );
       
        removeJButton=new JButton();
        removeJButton.setBounds(190,300,90,30);
        removeJButton.setText(" remove");
        contentPane.add(removeJButton);
       
       
       nextJButton=new JButton();
       nextJButton.setBounds(290,300,90,30);
        nextJButton.setText(" next");
        contentPane.add( nextJButton);
       
         // Parcel newParcel = new Parcel(idno);
       // end method createUserI
      checkJLabel=new JLabel();
      checkJLabel.setText("check");
        checkJLabel.setBounds(10,10,90,30);
        contentPane.add(checkJLabel);
      
      checkJTextField=new JTextField();
        checkJTextField.setBounds(120,10,90,30);
        contentPane.add( checkJTextField);
        checkJTextField.addKeyListener(new KeyAdapter()
        {public void keyPressed(ActionEvent e)
      {
        checkJTextFieldkeyPressed( e);
      }
      }
        
         );
        
        
        arriveatJLabel=new JLabel();
      arriveatJLabel.setText("arriveat");
      arriveatJLabel.setBounds(10,50,90,30);
        contentPane.add(arriveatJLabel );
      
      arriveatJTextField=new JTextField();
        arriveatJTextField.setBounds(120,50,190,30);
        contentPane.add(  arriveatJTextField);
        
        
       idJLabel=new JLabel();
      idJLabel.setText("id");
      idJLabel.setBounds(10,90,90,30);
        contentPane.add(idJLabel );
      
     idJTextField=new JTextField();
        idJTextField.setBounds(120,90,190,30);
        contentPane.add(  idJTextField);
          
          
          
          nameJLabel=new JLabel();
      nameJLabel.setText("name");
      nameJLabel.setBounds(10,130,90,30);
        contentPane.add(nameJLabel );
        
          nameJTextField=new JTextField();
       nameJTextField.setBounds(120,130,190,30);
        contentPane.add(nameJTextField);
          
          
          setTitle( "eclipse" ); // set title bar text
          setSize( 435, 390 ); // set window size
          setVisible( true );  // display window    // end method createUserInterface
      }            
               
     
     
    private void okJButtonactionPerformed(ActionEvent e)
     {String str="";
     Iterator pIterator=pArrayList.iterator();
     while(pIterator.hasNext())
     { Parcel current= (Parcel)pIterator.next();
     if(checkJTextField.getText().equals(current.getname()))
      str=current.getname();
     nameJTextField.setText(str);
     id=current.getid();
     }
     
     }
      /*
     private void okJButtonactionPerformed(ActionEvent e)
     {
     String str=checkJTextField.getText();
     
     
     Parcel current = (Parcel)hash.get(str);
     nameJTextField.setText(current.name);
     idJTextField.setText(current.id);
    }
    */ 
     
     
     private void scanJButtonactionPerformed( ActionEvent e)
     {nameJTextField.setText("");
      Date now=new Date();
      arriveatJTextField.setText( now.toString());
      idno++;
      idJTextField.setText(String.valueOf(idno));
     
     
     }
     
     private void checkJTextFieldkeyPressed( ActionEvent e)
     {
     
      }
     
    private void addJButtonactionPerformed( ActionEvent e)
     {  
     
        Parcel newParcel=new Parcel(idJTextField.getText(),nameJTextField.getText());
       //hash.put(newParcel.getid(),newParcel.getname());
      hash.put(newParcel.getid(),newParcel);
     
     }
     private void removeJButtonactionPerformed( ActionEvent e)
     
     {
     pArrayList.remove( id);
     }
     
     public static void main( String[] args ) {
      Transportation application = new Transportation();
        application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );   } // end method main} 
      

  3.   

    接上面
    class Parcel
    {
    String name;
    String address;
    String zip;
    String city;
    String state;
    String id;


    Parcel(String IDD,String n)
    {
    id=IDD;
    name=n;
    }





    void setaddress(String a)
    {address=a;
    }


    void setzip(String z)
    {zip=z;
    }


    void setstate(String s)
    {state=s;
    }

    void setcity(String c)
    {city=c;
    } String getid()
    {return id;
    }
    String getname()
    {return name;
    }

    String getaddress()
    {return address;
    }


    String getzip()
    {return zip;
    }


    String getstate()
    {return state;
    }

    String getcity()
    {return city;
    }



    }
      

  4.   

    忘了说明了,我那个先点scan,自动生成日期和序号,填好其他信息(check里不要填!!!!!!!!!!)然后点add,添加好几条了以后查询,chek里输入刚才有的一个序号,我把信息显示出来目前我只测试了查询后名字显示的功能,不行!!!!!!!!!!!!
      

  5.   

    没看懂你的程序要做什么add按钮没有触发任何事件
      

  6.   

    改了两个方法    private void okJButtonactionPerformed(ActionEvent e)
        {
            String str = "";
            {
                Parcel current = (Parcel) hash.get(checkJTextField.getText());
                str = current.getname();
                nameJTextField.setText(str);
                id = current.getid();
            }
        }
        private void addJButtonactionPerformed(ActionEvent e)
        {        Parcel newParcel = new Parcel(idJTextField.getText(),
                                          arriveatJTextField.getText());
            hash.put(newParcel.getid(),newParcel);
        }
      

  7.   

    晕 我写错了我这个是包裹的运输我本来用arraylist方法实现的,结果后来又用了hashmap发的时候结果忘了改add方法里的,造成了add是hash的,check变成了arraylist的不好意思啊,帮我再看一下,用arraylist,没有办法实现nameJTextField.setText(str);//为什么这里显示不出来啊?????????private void addJButtonactionPerformed( ActionEvent e)
    {  
    //pArrayList=new  ArrayList ();
        Parcel newParcel=new Parcel(idJTextField.getText());
            pArrayList.add(newParcel);
            position=pArrayList.size()-1;
    }这个是add,前面都一样,我用arraylist做的遍历,结果不行
      

  8.   

    上面那个帖子不用看了我那个name显示又莫名其妙好了
    新的问题又出来了,这个id又不显示了private void okJButtonactionPerformed(ActionEvent e)
     {String str="";
     Iterator pIterator=pArrayList.iterator();
     while(pIterator.hasNext())
     { Parcel current= (Parcel)pIterator.next();
     if(checkJTextField.getText().equals(current.getid()))
      str=current.getname();
     nameJTextField.setText(str);
     id=current.getid();
     idJTextField.setText(id);//这个id又不显示了
     
     }
     
     }
      

  9.   

    看的真晕,
    只想问一下id有值吗?
     id=current.getid();
     System.out.println("id:"+id);//这边打一下
     idJTextField.setText(id);//这个id又不显示了
      

  10.   

    原来还可以这么测试啊,谢谢啊呵呵,一直不知道怎么调试gui的界面,不知道怎么看这些方法里的值有没有显示,呵呵,现在总算知道怎么弄了
    主要这里不能删除和修改帖子,我也弄的晕了
    知道怎么错了,if没打括号