#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0

    vars in attributes to combine objects of 2 classes


    hi, i want to create an object out of 2 objects of different classes.
    like this: color.class
    Code:
    public class color{
    	private String name;
    
    	public color(String name){
    		this.name = name;
    		}
    	color color1 = new color(red);
    	color color2 = new color(green);
    
    	public getName(){
    		return Name;
    	}
    }
    paper.class [
    Code:
    ]
    public class paper{
    	private String size;
    
    	public paper(String size){
    		this.size = size;
    		}
    	paper paper1 = new paper(A4);
    	paper paper2 = new paper(A3);
    		
    	public getSize(){
    		return size;
    	}
    }
    now i want to combine them into a third object. the problem is that i want that the user can select the objects. he sets the value of a vars in a gui. this vars should be used to select diffrent objects and combine them.
    like: objectclass.class
    Code:
    public class objectclass{
    	private String name;
    	private String size;
    	private int varColor = 2 // is set by gui
    	private int varPaper = 1 // is set by gui	
    
    	public objectclass(String name,String size){
    		this.name = name;
    		this.size = size
    		}
    
    \\on button click
    	objectclass newPaper = new objectclass(color."color"+varColor.getName(), paper."paper"+varPaper.getSize());
    	}
    as u can see the problem is that "color"+varColor is not accepted as attribute.
    i guess i could use cases but iam going to have over 100 objects and at least 3 classes.
    so the question is: how to get this running.

    the classes are also used as some kind of databases for different stats. some classes have base stats and others have changeable user stats.
    any ideas of simplyfying my ideas. maybe some .txt readout for future balance fixes?
    Last edited by john1337; October 5th, 2012 at 05:22 PM. Reason: forgot title; epic fail ;-)
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    color."color"
    Can you explain what you are trying to do in that statement?
    Color is a poor name for your class. Java SE has a Color class.
    How about MyColor?
    Can you add a method to your MyColor class that takes a String ("color") and returns a String with the content you want.

IMN logo majestic logo threadwatch logo seochat tools logo