public void defineField (String fieldname, String guiname, String type) {
        try {
            if (fields.contains(fieldname)) return;
            if (guiname == null) guiname = fieldname;
            fields.add(fieldname);
            fieldtypes.put(fieldname, type);
            fieldguinames.put(fieldname, guiname);
            addGuiComponent(fieldname);
            if (cls != null) {
                Field field = cls.getField(fieldname);
                // if obj==null we get an undocumented exception in case the field
                // is NOT static, so we assume that the field is appropriately
                // static for now.
                setField(fieldname, field.get(obj), true);
            }
        }
        catch (NoSuchFieldException e) {
            System.out.println("Cls:" + cls);
            throw new JGameError("Field " + fieldname + " not found.");
        }
        catch (IllegalAccessException e) {
            throw new JGameError("Field " + fieldname + " has access error.");
        }
    }