swing 使用textFidle.getText()报错,提示让我把textFidle改成final类型的

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();				
    }			
    }		
    });

我想获取文本框里面用户输入的内容 ,请问应该如何解决?

动感光波biubiubiubiu
浏览 841回答 2
2回答

快乐的小牛妞

https://job.m.imooc.com
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java