java - How to add a new static parameter without affecting the olders one? -


i have read user name of fabricant , type of key. have defined class "article" string fabricant , list of types of keys. if have add new type it's okay if have add new fabricant, new name of fabricant changes 1 before. code( class allarticle it's set of articles):

cle.mtype = textntype.gettext(); set <string> ntype = new hashset<>(); boolean found = false; string antes =  article.mfabricant;  allarticle allarticle = new allarticle(); allarticle.importfrom("article.txt"); for(string fabric : allarticle.getfabricants()){      if(fabric.equals(antes)){         found = true;         allarticle.gettypeforfabricant(antes).add(textntype.gettext());         allarticle.exportto("article.txt");        } } if(found == false){      ntype.add(textntype.gettext());     allarticle.addarticle(new article(antes,ntype));     allarticle.exportto("article.txt"); } 

with debug have founded problem inside second if in add function. think has related fact variable mfabricant static cant change because need in others jframe. function addarticle , class article:

public void addarticle(article article){    marticles.add(article); }  public class article {  protected static string mfabricant; protected set<string> mtype;} 

this code firs jframe value , itembox:

    article.mfabricant = (string) articlesbox.getselecteditem();     cle.mfabricant = (string) articlesbox.getselecteditem();     typefe obj = new typefe();     obj.setvisible(true);     dispose(); 

and here code select type of key based on fabricant:

 public typefe() {     initcomponents();     setlocationrelativeto(null);     setresizable(false);     settitle("type");     allarticle allarticle = new allarticle();     allarticle.importfrom("article.txt");     set <string> marticles;     marticles = allarticle.gettypeforfabricant(article.mfabricant);     for(string article : marticles){         typebox.additem(article);     }   } 

the variable mfabricant, being static in nature, shared across instances of article means setting value through article instance over-write instances.

please share code using in jframe.

i suggest change 'mfabricant' instance field , pass reference of either mfabricant or article instance jframe.

change typefe class constructor take fabricant parameter:

public typefe(final string fabricant) {    ....    marticle = allarticles.gettypeforfabricant(fabricant);    ..... } 

pass selected fabricant in typrfe initialization:

final string fabricant =  (string) articlesbox.getselecteditem(); typefe obj = new typefe(fabricant); obj.setvisible(true); dispose(); 

you can search fabricant value in list of articles , add type if article exist or add new article.


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -