swing - Java GUI using Netbeans -


i have problem writing things using .settext in textfield if writing command in code of frame in order set text in textfield in frame know textfields in netbeans preloaded gui have private method. suggestions overcome problem

the code calling other frame write in it,

private void jcombobox2actionperformed(java.awt.event.actionevent evt){                                                tx_customize l= new tx_customize();    env_region = jcombobox2.getselectedindex();     l.lf();    system.out.println(env_region);  }  

where other frame

public void lf(){     envi = s.env_region;     system.out.println(envi);      switch (envi)             {                 case 1:                      penetration.settext("21.5");                      lnf.settext("10");                     system.out.println("error1");                     break;`                     case 0:                      penetration.settext("16.5");                      lnf.settext("8");                     system.out.println("error0");                     break;                  case 2:                     penetration.settext("11");                      lnf.settext("6");                     system.out.println("error2");                     break;                  case 3:                      penetration.settext("7");                      lnf.settext("6");                     system.out.println("error3");                     break;                  default : system.out.println("error");break;              } } 

this has nothing swing , general oops practices , java: if need allow 1 class able change state of 2nd class, give 2nd class public methods objects of first class can call. can include wrapper methods if need call private methods.

for more detailed answer, must ask more detailed question, 1 includes pertinent code.


edit regarding comment:

.the code enters didn't wirte in textfields "penetration , lnf" in 2nd frame display system.out.println("error") in whatever case choose combo box in first frame ...and think because these private in preloaded code know way to

nah, has absolutely nothing public or private , bug in code. if access issue, code wouldn't compile. problem here:

private void jcombobox2actionperformed(java.awt.event.actionevent evt)  {                                              tx_customize l= new tx_customize(); // *********    env_region = jcombobox2.getselectedindex();     l.lf();    system.out.println(env_region); }  

you're creating new tx_customize, calling methods on it, , expecting magically change tx_customize object, 1 displayed, , java doesn't work way -- there no magic. if want change state of displayed tx_customize object, must call methods on same object, not new tx_customize create in method.


edit 2

other general problems:

  • your program should have 1 main jframe.
  • if absolutely need display window secondary first, should dialog such jdialog.
  • you new swing, , because of this, should not use swing code generator hampering ability learn how library works. instead code swing hand, using tutorials.
  • you want study basic java well, learn building blocks of language, how objects work, how they're different variables, etc. go through intro java text book or tutorial immensely. helped me.
  • learn , follow java naming conventions including giving classes names begin upper case letter , methods , variables names begin lower case letter. matters when want others (us!!) understand code.

edit 3
state:

so mean should call lf method : tx_customize.lf();

heck no. require method static. suggesting somehow reference actual displayed other object , call method off of that. how reference depend on lot of things including code you've not shown us.


edit 4
ask:

i want ask question @hovercraftfullofeels main use of reference because first time me hear

your problem (i believe -- can't sure we've seen limited code) due having more 1 tx_customize object in existence. i'm guessing tx_customize extends jframe, , you've got 1 of these you're displaying. in jcombobox2actionperformed method create second tx_customize instance , try call methods on it, have no effect on original tx_customize object. instead must call method on actual displayed tx_customize object.

please understand variable not same thing object, , reference (non-primitive) variables can refer objects. reference i'm referring to. need variable you're calling lf() on (although should re-name method) refer actual displayed tx_customize object.

to this, class holds jcombobox2actionperformed method must have variable refers displayed tx_customize. again, please see answer similar type of question can find here, shows example this, of gaining reference through constructor parameter, , calling method on variable holds reference in event-driven setting.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -