public void actionPerformed(ActionEvent e){
    Object obj=e.getSource();  
    if(obj==save){
      if(_map.getName().length()==0){
        String s = JOptionPane.showInputDialog("Please enter the name for the xml file: ");
        if(s==null){
          return;
        }
        while(s.length()==0){
          s = JOptionPane.showInputDialog("Please enter a valid name!\nPlease enter the name for the file: ");
          if(s==null){
            return; 
          }
        }
        _map.setName(s);
      }
      if(_map.mygraph.getScale()==0.0){
        String feet = JOptionPane.showInputDialog("Please enter the feet-per-pixel for the file: ");
        if(feet==null){
          return;
        }             
        while(feet.length()==0){
          try{
            double num=Double.parseDouble(feet);
            break;
          }catch(Exception e1){
            feet = JOptionPane.showInputDialog("Please enter a valid number!\nPlease enter the feet-per-pixel for the file: ");
            if(feet==null){
              return; 
            }
          }
        }
        _map.mygraph.setScale(Double.parseDouble(feet));
      }
      _map.printOut();
      String display="File Saved.";
      _textarea.setText(display);
    }else if(obj==saveas){
      //save as a file DONE
      String s = JOptionPane.showInputDialog("Please enter the name for the xml file: ");
      if(s==null){
        return; 
      }
      while(s.length()==0){
        s = JOptionPane.showInputDialog("Please enter a valid name!\nPlease enter the name for the file: ");
        if(s==null){
          return; 
        }
      }
      if(_map.mygraph.getScale()==0.0){
        String feet = JOptionPane.showInputDialog("Please enter the feet-per-pixel for the file: ");
        if(feet==null){
          return; 
        }
        while(true){
          try{
            double num=Double.parseDouble(feet);
            break;
          }catch(Exception e1){
            feet = JOptionPane.showInputDialog("Please enter a valid number!\nPlease enter the feet-per-pixel for the file: ");
            if(feet==null){
              return; 
            }
          }
        }
        _map.mygraph.setScale(Double.parseDouble(feet)); 
      }
      
      _map.setName(s);
      _map.printOut();
      String display="File Saved As "+s+".";
      _textarea.setText(display);
    }else if(obj==openfile){
      //openfile DONE
      /*String s = JOptionPane.showInputDialog("Open xml File: ");
      if(s==null){
        return; 
      }*/
      
      JFileChooser fc=new JFileChooser(System.getProperty("user.dir"));
      fc.setDialogTitle("Please choose map xml file");
      fc.setDragEnabled(false);
      File file;
      int val;
      String s;
      val=fc.showOpenDialog(this);
      if(val==JFileChooser.CANCEL_OPTION || val==JFileChooser.ERROR_OPTION){
        return;
      }
      file = fc.getSelectedFile();
      s=file.getName();
      while(true){
        try{
          _map.mygraph=new Graph(s);
          _map.setName(s);
          _map.setImage(_map.mygraph.getImageName());
          break;
        }catch(Exception e1){
          val=fc.showOpenDialog(this);
          if(val==JFileChooser.CANCEL_OPTION || val==JFileChooser.ERROR_OPTION){
            return;
          }
          file = fc.getSelectedFile();
          s=file.getName();
        }
      }
      _map.changeNotify();
      String display="File - "+s+" Opened.";
      _textarea.setText(display);
    }else if(obj==newfile){
      //get the name for the image file
      JFileChooser fc=new JFileChooser(System.getProperty("user.dir"));
      fc.setDialogTitle("Please choose Image File");
      fc.setDragEnabled(false);
      int val;
      File file;
      String imgnm;
      BufferedImage img;
      while(true){
        try{
          val=fc.showOpenDialog(this);
          if(val==JFileChooser.CANCEL_OPTION || val==JFileChooser.ERROR_OPTION){
            return;
          }
          file = fc.getSelectedFile();
          imgnm=file.getName();
          img=ImageIO.read(file);
          if(img==null){
            continue;
          }
          break;
        }catch(Exception e1){
        }
      }
      
      //get the name for the new file  
      String s=JOptionPane.showInputDialog("Please enter the name for new xml file: ");
      if(s==null){
        return; 
      }
      while(s.length()==0){
        s = JOptionPane.showInputDialog("Please enter a valid name!\nPlease enter the name for the xml file: ");
        if(s==null){
          return; 
        }
      }
      //get the feet per pixel constant
      String feet= JOptionPane.showInputDialog("Please enter feet per pixel: ");
      if(feet==null){
        return; 
      }
      while(true){
        try{
          double num=Double.parseDouble(feet);
          break;
        }catch(Exception e1){
          feet = JOptionPane.showInputDialog("Please enter a valid number!\nPlease enter feet per pixel: ");
          if(feet==null){
            return; 
          }   
        }
      }
      _map.mygraph=new Graph();
      _map.mygraph.setImageName(imgnm);
      _map.setImage(imgnm);
      _map.setName(s);
      _map.setScaleFeet(Double.parseDouble(feet));
      _map.changeNotify();
      String display="New File - "+s+" Created.";
      _textarea.setText(display); 
    }else if(obj==insertloc){
      _map.setMode(_map.INSERTLOC);
      setTitle("Map Editor(Insert Location Mode)");
      String display="Insert Location Mode:\n\n";
      display+=("Legal Operations:\n"+
        "1.Single Click: add a point\n or select the current location\n"+
        "2.Double Click: open a dialog that\n shows the property of the location\n"+
        "3.Click and Drag: change position\n of a point\n");
      _textarea.setText(display); 
    }else if(obj==deleteloc){
      _map.setMode(_map.DELETELOC);
      setTitle("Map Editor(Delete Location Mode)");
      String display="Delete Location Mode:\n\n";
      display+=("Legal Operations:\n"+
        "1.Single Click: delete a point\n and paths of the point\n"+
        "2.Double Click: open a dialog that\n shows the property of the location\n");
      _textarea.setText(display); 
    }else if(obj==insertpath){
      _map.setMode(_map.INSERTPATH);
      setTitle("Map Editor(Insert Path Mode)");
      String display="Insert Path Mode:\n\n";
      display+=("Legal Operations:\n"+
        "1.Click and Drag: add a path from\n start location to end location\n"+
        "2.Double Click: open a dialog that\n shows the property of the location\n");
      _textarea.setText(display); 
    }else if(obj==deletepath){
      _map.setMode(_map.DELETEPATH);
      setTitle("Map Editor(Delete Path Mode)");
      String display="Delete Path Mode:\n\n";
      display+=("Legal Operations:\n"+
        "1.Click and Drag: delete a path from\n start location to end location\n"+
        "2.Double Click: open a dialog that\n shows the property of the location\n");
      _textarea.setText(display); 
    }else if(obj==location){
      _map.setMode(_map.PROPERTY);
      setTitle("Map Editor(Location Properties Mode)");
      String display="Location Properties Mode:\n\n";
      display+=("Legal Operations:\n"+
        "1.Single Click: open a dialog that\n shows the property of the location\n"+
        "2.Double Click: open a dialog that\n shows the property of the location\n");
      _textarea.setText(display); 
    }else if(obj==find){
      _map.setMode(_map.FIND);
      setTitle("Map Editor(Find Mode)");
      int index=getIndex();
      if(index==-1){
        return;     
      }
      //display it on the textarea
      String display="Find Mode:\n\nLocation Property:\nName:"+_map.mygraph.locations[index].getName()+"\n(x,y)=("
          +_map.mygraph.locations[index].getPoint().getX()+","
          +_map.mygraph.locations[index].getPoint().getY()
          +")\nID="+_map.mygraph.locations[index].getID()+"\n\n";
      display+="If the point is not in the center of\n"+ 
        "the scrollpane,\n"+"that is because it is too close to\n" 
        +"the left or top of the image.\n";
      _textarea.setText(display); 
      //set the point to be the center of the map
      _map.mygraph.setSelectIndex(index);
      _map.setCurrProperty(index);
      _zoomPane.setCenter(_map.mygraph.locations[index].getPoint());
      _map.changeNotify(); 
    }else if(obj==directions){
      _map.setMode(_map.DIRECTIONS);
      setTitle("Map Editor(Directions Mode)");
      int indexFrom=getIndexFrom();
      if(indexFrom==-1){
        return; 
      }
      int indexTo=getIndexTo();
      if(indexTo==-1){
        return; 
      }
      _map.mygraph.setDir(indexFrom,indexTo);
      _map.changeNotify();
      String notification=_map.mygraph.findPrintDirection();
      _textarea.setText("Directions:\n\n"+notification);
    }else if(obj==readme){
      setTitle("Map Editor(Help Mode)");
      String s="Readme:\n\nPeople in my group:\nLirong Yuan: yuan27\nJerry Ma: ma127\n\n"+
        "List of features that work:\n1.Four file operations:\n (1)New File (2)Open File\n (3)Save "+
        "(4)Save As\n2.Five modes:\n (1)Add Loc (2)Delete Loc\n (3)Add Path (4)Delete Path\n"+
        " (5)Location Property\n3.Two functions:\n (1)Find (2)Get Directions\n\n"+
        "List of features that do not work:\nNone.\n\nExtra features:\n"+
        "1.Help menu.\n2.Information panel.(this)\n\n"+
        "About my implementation:\n1.Location: red\n2.Path: yellow\n3.Direction: blue\n"+
        "4.Find point: green\n\nThanks for reading this!\n";
      _textarea.setText(s);
    }else if(obj==fileinfo){
      setTitle("Map Editor(File Info Mode)");
      String filename=_map.getName();
      if(filename.length()==0){
       filename="(Not defined yet)"; 
      }
      String imgnm=_map.mygraph.getImageName();
      String sfpps;
      double sfpp=_map.mygraph.getScale();
      if(sfpp==0.0){
        sfpps="(Not defined yet)";
      }else{
        sfpps=""+sfpp;
      }
      String s="File name:\n"+filename+"\n\nImage name:\n"+imgnm+"\n\nScale-Feet-Per-Pixel:\n"+sfpps;
      _textarea.setText(s);
    }
  }