JPanel pname = new JPanel();
pname.setLayout(null);
JTextField personName = new JTextField();
personName.setFont(new Font("",Font.BOLD,25));
personName.setBounds(0,15,240,50);
addPerson.add(pname);
pname.add(personName);
JPanel btn_sub = new JPanel();
btn_sub.setLayout(null);
JButton submit = new JButton("确定");
submit.setFont(new Font("",Font.BOLD,25));
submit.setBounds(80, 20, 120, 40);
addPerson.add(btn_sub);
btn_sub.add(submit);
submit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
try {
FileWriter file = new FileWriter(new File(path),true);
String inString = personName.getText();
//这里的personName报错
//提示写的这个:Cannot refer to a non-final variable personName inside an inner class defined in a different method
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});我想获取文本框里面用户输入的内容 ,请问应该如何解决?
添加回答
举报
0/150
提交
取消