Auto filling a jTextfield in java swing

后端 未结 1 1904
长情又很酷
长情又很酷 2021-01-29 13:38

I am creating a small system using swing via netbeans(I must say i am new to swing). look at the below image .

\"ent

相关标签:
1条回答
  • 2021-01-29 13:59

    So, you want to pass the String value from one class to another.

    Well, the easiest and (best) way to achieve this is by creating the 2nd class as an inner class of the first class.

    • All you have to do is to Paste your 2nd class code inside your 1st class code (Don't paste it inside the main method)

    • Remove the static word from your 2nd class's main method

    • Declare a String in your 1st class as follows,

      String StudentId;

    • After you collect the Id from the user, intialize the above mentioned String as,

      String StudentId = "student_id_to_show";

    • Now,in your 2nd class code(which is inner class of the 1st class), set the text of the jTextField as,

      jTextField.setText(StudentId);

    All done,Cheers!!!

    0 讨论(0)
提交回复
热议问题