Im not sure how to get the data from my text field

送分小仙女□ 提交于 2019-11-28 14:40:01

The variable textField is local to main. If you want to access it from actionPerformed, you'll need to change it to an instance variable.

Yeah. I agree with @jpm. You need to declare it as an instance variable. Do the following:-

  public class test extends Component {
       //Declare the variable here.
       private static JTextField textfield;

    public static void main(String[] args) {
       //Whenever you use the textfield use like this. Remove the keyword 'JTextField'.
       textfield = new JTextField();
  }
  }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!