swing - Getting the text property from an object in java -


i'm working on project in java have vector contains objects contains jtextfields, checkboxes or blobs. need able text property such textfield.

i have code:

for(int = 0; < gridvalues.size(); i++) {         object value = gridvalues.elementat(i);         if (value instanceof jtextfield)         {          } }  

i'm not sure how text value object. when go through list first itemis of type jtextfield comes in if statement, should text property tis object have no idea how. gridvalues vector possible textfields, checkboxes , blobs.

you text value first casting jtextfield , calling gettext() on it:

// after checking value in fact refers jtextfield string text = ((jtextfield)value).gettext(); 

e.g.,

if (value instanceof jtextfield) {     string text = ((jtextfield)value).gettext();     // here use text whatever it's needed } 

but should consider changing program design, since it's use of mixed types in collections makes brittle program, in other words, program have bugs time minor change made.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -