java 如何从文本框中获取字符串?

这个方法不知为何被弃用了,还有什么其他的办法吗?
// GUI components for the username
logonFieldsPanel = new JPanel();
logonFieldsPanel.setLayout(new GridLayout(2,2,5,5));
usernameLabel = new JLabel("Enter Username: ");
logonFieldsPanel.add(usernameLabel);
username = new JTextField(10);
logonFieldsPanel.add(username);
还有password的,但是这里写不下了..

弃用了还是可以用的,如果是空指针的话,password这个对象应该是空的,你看下是不是没有创建过这个对象追问

JPasswordField password;
JTextField username;
肯定有这个对象啊,没有对象的话也不能运行吧...

追答

JPasswordField password;
JTextField username;
这样肯定是空的
不知道你用的什么框架
估计是你前台的jsp代码的问题,要么就是配置的问题

追问

上面还有GUI来输入用户名和密码呢..
补充了,能看看吗0 0

追答

sorry啊,GUI的我不懂的,我做java web方面

温馨提示:答案为网友推荐,仅供参考
相似回答