Auto filling a jTextfield in java swing

蹲街弑〆低调 提交于 2019-12-02 13:30:15

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!!!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!