• Post Reply Bookmark Topic Watch Topic
  • New Topic

Building JTree - Like Object  RSS feed

 
Nicolas Viollin
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !!
I would like to build an Object of class X which normally have a list of Child of class Y, but can also have Childs of class X.
Ex:
Object X
Object Y
Object Y
Object X
Object Y
.
.
Object Y
Object X
Object Y
Object X
Object Y
Object X
Object Y
The thing is Object X are only here to keep Object Y grouped together so of course the access methods have nothing in common....
Ex:
public class X{
public X(){}
// to get Object at position index
public ?? get(int index){}
// to remove object at position index
public ?? remove(int index){}
// to add an object in the list
public void add(??? object){}
// get the number of object in list
public int count(){ return count; }
....
...
..
.
}
public class Y{
public Y(){}
// to retreive object name
public String getName(){ return name; }

// to retreive object level
public int getLevel(){ return level; }
....
...
..
.
}
thanks in advance for any help !!
bye !
Nico
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could make a interface that both X and Y share:

Then your methods can return XorY.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!