Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object Context

Status
Not open for further replies.

entius

Instructor
Mar 20, 2001
2
ES
Hi
i'll show you several codes, the first ones work but then not, i'd like to know how to make it works ...
(thanks to iza & globos, i need not to "call" directly the class, you'll see):
///////////////////
this is the code that don't change
///////////////////
list = new String[2];
list[0] = "SCENA";
list[1] = "QUERY";

DataObjectScena = new DataObjectScena();
DataObjectQuery = new DataObjectQuery();

classList = new Object[2];
classList[0] = DataObjectScena;
classList[1] = DataObjectQuery;

public void handle (Object item) {
// item is an object that is only useful
// to decide which object-listModel i
// have to call.

for (int i=0; i<list.length; i++) {
if ( item.toString().equals(list) ) {
///////////////////
and this is the key code
///////////////////
a_JList.setListData
(((DataObjectScena)classList[0]).methods));
}}
///////////////////
it works, but always the method of DataObjectScena
///////////////////
a_JList.setListData
(classList[0].methods);
}}
///////////////////
it doesn't works
///////////////////
a_JList.setListData
(((classList[0])classList[0]).methods);
}}
///////////////////
it doesn't works, neither
///////////////////
of course i could build if ... and use (DataObjectScena)
else if ... and use (DataObjectQuery), but what about if i have 50 kinds of classes???
 
Well, as you would have to add 50 lines to the array if you have 50 classes, instead of using an if, if else, etc. statement, you could just assign them all to a case statement, each new class would only need a single addition to that statement which would be as easy as adding to an array of names.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top