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報(bào)錯(cuò)
????//提示寫的這個(gè):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();
????}
????}
????});我想獲取文本框里面用戶輸入的內(nèi)容 ,請(qǐng)問應(yīng)該如何解決?
swing 使用textFidle.getText()報(bào)錯(cuò),提示讓我把textFidle改成final類型的
動(dòng)感光波biubiubiubiu
2018-06-26 17:41:20