Access GUI components from another class

前端 未结 5 2065
遇见更好的自我
遇见更好的自我 2020-12-06 15:34

I\'m new to Java and I\'ve hit a brick wall. I want to access GUI components (that have been created in one class) from another class. I am creating a new GUI class from one

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 15:55

    here i add a simple solution hope it works good,

    Form A

    controls

    Textfield : txtusername

        FormB fb = new FormB();
        fb.loginreset(txtusername); //only textfield name no other attributes
    

    Form B
    to access FormA's control

     public void ResetTextbox(JTextField jf)
     {
         jf.setText(null); // or you can set or get any text
     }
    

提交回复
热议问题