JAVA之路
JAVA之路漫漫

2008年4月16日

selectButton.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent e){
    
    if(checkFloorNo.isSelected()&&!checkNo.isSelected()){
     worker.setSql("SELECT * FROM worker WHERE floorNo='"+worker.getFloorNo()+"'");
     controller.processModifyWorker(worker);
     System.out.println(worker.getSql());
     num.setFirstIndex(controller.getWorkerList().indexOf(controller.getWorkerList().get(0)));
     num.setInt(0);
     num.setEndIndex(controller.getWorkerList().size()-1);
     System.out.println(num.getFirstIndex());
     System.out.println(num.getInt());
     System.out.println(num.getEndIndex());
     
     noText.setText(controller.getWorkerList().get(num.getInt()).getNumber());
     floorNoText.setText(controller.getWorkerList().get(num.getInt()).getFloorNo());
     nameText.setText(controller.getWorkerList().get(num.getInt()).getName());
     ageText.setText(controller.getWorkerList().get(num.getInt()).getAge());
     sexText.setText(controller.getWorkerList().get(num.getInt()).getSex());
     telText.setText(controller.getWorkerList().get(num.getInt()).getTel());
     state.setText("信息以找到,当前显示的是"+controller.getWorkerList().get(num.getInt()).getFloorNo()+"第一条信息");
     
    }
    else if(!checkFloorNo.isSelected()&&checkNo.isSelected()){
     worker.setNumber(numberText.getText());
     worker.setSql("SELECT * FROM worker WHERE number='"+worker.getNumber()+"'");
     controller.processModifyWorkerText(worker);
     noText.setText(worker.getNumber());
     floorNoText.setText(worker.getFloorNo());
     nameText.setText(worker.getName());
     ageText.setText(worker.getAge());
     sexText.setText(worker.getSex());
     telText.setText(worker.getTel());
     state.setText("信息以找到");
    }
   firstButton.addActionListener(new ActionListener(){
     public void actionPerformed(ActionEvent e){
      if(num.getInt()==num.getFirstIndex()){
        JOptionPane.showMessageDialog(firstButton, "当前位于第"+controller.getWorkerList().indexOf(controller.getWorkerList().get(num.getFirstIndex()))+"条信息处");
      }
       
      else{ 
       num.setInt(num.getFirstIndex());
       System.out.println(num.getInt());
       noText.setText(controller.getWorkerList().get(num.getInt()).getNumber());
       floorNoText.setText(controller.getWorkerList().get(num.getInt()).getFloorNo());
       nameText.setText(controller.getWorkerList().get(num.getInt()).getName());
       ageText.setText(controller.getWorkerList().get(num.getInt()).getAge());
       sexText.setText(controller.getWorkerList().get(num.getInt()).getSex());
       telText.setText(controller.getWorkerList().get(num.getInt()).getTel());
       state.setText("信息以找到,当前显示的是"+controller.getWorkerList().get(num.getFirstIndex()).getFloorNo()+"第一条信息");
      }
     }
    });
    lastButton.addActionListener(new ActionListener(){
     public void actionPerformed(ActionEvent e){
      if(num.getInt()==num.getFirstIndex()){
       JOptionPane.showMessageDialog(lastButton, "当前位于第"+controller.getWorkerList().indexOf(controller.getWorkerList().get(num.getFirstIndex()))+"条信息处");
      }
      else{ 
       num.setInt(num.getInt()-1);
       System.out.println(num.getInt());
       noText.setText(controller.getWorkerList().get(num.getInt()).getNumber());
       floorNoText.setText(controller.getWorkerList().get(num.getInt()).getFloorNo());
       nameText.setText(controller.getWorkerList().get(num.getInt()).getName());
       ageText.setText(controller.getWorkerList().get(num.getInt()).getAge());
       sexText.setText(controller.getWorkerList().get(num.getInt()).getSex());
       telText.setText(controller.getWorkerList().get(num.getInt()).getTel());
       state.setText("信息以找到,当前显示的是"+controller.getWorkerList().get(num.getInt()).getFloorNo()+"上一条信息");
      }
      }
    });
    nextButton.addActionListener(new ActionListener(){
     public void actionPerformed(ActionEvent e){

      if(num.getInt()==num.getEndIndex()){
       JOptionPane.showMessageDialog(nextButton, "当前位于第"+controller.getWorkerList().indexOf(controller.getWorkerList().get(num.getEndIndex()))+"条信息处");
      }
      else{ 
       num.setInt(num.getInt()+1);
       System.out.println(num.getInt());
       noText.setText(controller.getWorkerList().get(num.getInt()).getNumber());
       floorNoText.setText(controller.getWorkerList().get(num.getInt()).getFloorNo());
       nameText.setText(controller.getWorkerList().get(num.getInt()).getName());
       ageText.setText(controller.getWorkerList().get(num.getInt()).getAge());
       sexText.setText(controller.getWorkerList().get(num.getInt()).getSex());
       telText.setText(controller.getWorkerList().get(num.getInt()).getTel());
       state.setText("信息以找到,当前显示的是"+controller.getWorkerList().get(num.getInt()).getFloorNo()+"下一条信息");
      }
     }
    });
    endButton.addActionListener(new ActionListener(){
     public void actionPerformed(ActionEvent e){

      if(num.getInt()==num.getEndIndex()){
       JOptionPane.showMessageDialog(endButton, "当前位于第"+controller.getWorkerList().indexOf(controller.getWorkerList().get(num.getEndIndex()).getFloorNo())+"条信息处");
      }
      else{ 
       num.setInt(num.getEndIndex());
       System.out.println(num.getInt());
       noText.setText(controller.getWorkerList().get(num.getInt()).getNumber());
       floorNoText.setText(controller.getWorkerList().get(num.getInt()).getFloorNo());
       nameText.setText(controller.getWorkerList().get(num.getInt()).getName());
       ageText.setText(controller.getWorkerList().get(num.getInt()).getAge());
       sexText.setText(controller.getWorkerList().get(num.getInt()).getSex());
       telText.setText(controller.getWorkerList().get(num.getInt()).getTel());
       state.setText("信息以找到,当前显示的是"+controller.getWorkerList().get(num.getEndIndex()).getFloorNo()+"最后一条信息");
      }
     }
    });
   }
  });
  
  checkFloorNo.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent e){
    if(checkFloorNo.isSelected()){
     state.setText("正在以-栋-为单位查找你想要的信息");
     worker.setFloorNo(comboFloorNo.getSelectedItem().toString());
     checkNo.setSelected(false);
     comboFloorNo.setEnabled(true);
     numberText.setEditable(false);
     firstButton.setEnabled(true);
     lastButton.setEnabled(true);
     nextButton.setEnabled(true);
     endButton.setEnabled(true);
     comboFloorNo.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e){
       
       
       worker.setFloorNo(comboFloorNo.getSelectedItem().toString());
       controller.processWorkerListClear();
      
       System.out.println(comboFloorNo.getSelectedItem().toString());
      }
     });
     
    }
   }
  });
  
  
  checkNo.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent e){
    if(checkNo.isSelected()){
     checkFloorNo.setSelected(false);
     comboFloorNo.setEnabled(false);
     numberText.setEditable(true);
     firstButton.setEnabled(false);
     lastButton.setEnabled(false);
     nextButton.setEnabled(false);
     endButton.setEnabled(false);
     state.setText("正在以-编号-的形式查找精确信息");
      }
    
   }
  });
  num.setFirstIndex(controller.getWorkerList().indexOf(controller.getWorkerList().get(0)));
     num.setInt(0);
     num.setEndIndex(controller.getWorkerList().size()-1);

每一次进入SELECTButton  时出现索引错误,nextButton, lastButton不能得到预想的效果

posted @ 2008-04-16 13:52 夏菁瑞 阅读(90) | 评论 (0)编辑 收藏
仅列出标题