public void getFields(Class klass) {
   int num = klass.getFields().length;
   // if(klass.getFields().length = null){
   String length = "" + num;
   if (!length.isEmpty()) {
     textArea3.setText("The class has " + length + " fields");
   } else {
     textArea3.setText("The class has no fields");
   }
 }
Exemple #2
0
  private MutableTreeNode populateAttributes(CavityDBObject obj) {
    DefaultMutableTreeNode tree = new DefaultMutableTreeNode("attrs");
    Class cls = obj.getClass();
    for (Field f : cls.getFields()) {
      int mod = f.getModifiers();
      if (Modifier.isPublic(mod) && !Modifier.isStatic(mod)) {
        String fieldName = f.getName();
        try {
          Object value = f.get(obj);
          tree.add(
              new DefaultMutableTreeNode(String.format("%s=%s", fieldName, String.valueOf(value))));

        } catch (IllegalAccessException e) {
          // do nothing.
        }
      }
    }
    return tree;
  }