Example #1
0
  public static void getUserInfo(String path, String fileName, Object[] o) throws Exception {
    Map userMap = new HashMap();
    if (o.length > 0) {
      for (Object s : o) {
        JTextComponent f = (JTextComponent) s;
        if (!StringUtil.isEmptyString(f.getText().trim())) {
          if (f.getClass() == JTextField.class) {
            JTextField jtf = (JTextField) f;
            logger.debug("[key = " + jtf.getName() + ",value = " + jtf.getText().trim() + "]");
            userMap.put(jtf.getName(), jtf.getText().trim());
          }
          if (f.getClass() == JPasswordField.class) {
            JPasswordField jpf = (JPasswordField) f;
            logger.debug("[key = " + jpf.getName() + ",value = " + jpf.getText().trim() + "]");
            userMap.put(jpf.getName(), jpf.getText().trim());
          }
        }
      }
    }

    writeFile(userMap, path, fileName);
  }
Example #2
0
 public static void setUserInfo(String path, String fileName, Object[] o)
     throws FileNotFoundException, Exception {
   if (!new File(path + fileName).exists()) {
     return;
   }
   ObjectInputStream in = new ObjectInputStream(new FileInputStream(path + fileName));
   Map userMap = (Map) in.readObject();
   in.close();
   if (o.length > 0)
     for (Object s : o) {
       JTextComponent f = (JTextComponent) s;
       if (f.getClass() == JTextField.class) {
         JTextField jtf = (JTextField) f;
         jtf.setText(
             userMap.get(jtf.getName()) == null ? "" : (String) userMap.get(jtf.getName()));
       }
       if (f.getClass() == JPasswordField.class) {
         JPasswordField jpf = (JPasswordField) f;
         jpf.setText(
             userMap.get(jpf.getName()) == null ? "" : (String) userMap.get(jpf.getName()));
       }
     }
 }