java - how i can name all my objectes in array of objectes with Jtextfield -
http://i.stack.imgur.com/68ou3.png have class named trader , have class named product.
task is:
the trader should buy many products (an object array of class
product)
now want user enter name of product in jtextfield (using product k=new product();)
want jtextfield find corresponding object product objects (somehow using/implementing equals(k) method) , stored in array of objects has bought (product) in trader every time adds product way.
how can implemented?
you can't expect user enter variable name of object jtextfield , add object accordingly. if can reflection, not used in manner.
you can perhaps create product class name attribute within product class:
class product { private string name; //your other attributes here.. public product(string name){ this.name = name; } } as user enters name of product textfield , click button, can add product according name such:
@override actionperformed(actionevent e){ traderlist.add(new product(txtproduct.gettext())); } the traderlist can arraylist stores various products. may add checks on product name before adding them list.
Comments
Post a Comment