private void pushButtonActionPerformed(java.awt.event.ActionEvent evt)
{
final int c=0;
final JDialog d=new JDialog();
JLabel l=new JLabel("Enter the Element :");
JButton but1=new JButton("OK");
JButton but2=new JButton("Cancel");
final JTextField f=new JTextField(10);
JPanel panel = new JPanel();
but1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
c=Integer.parseInt(f.getText());
d.setVisible(false);
d.dispose( );
}
});
but2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
d.setVisible(false);
d.dispose( );
}
});
}
我正在使用Netbeans 7.1.1。这是我的代码,在这里我将“c”声明为“final int”,但是当我输入“c=Integer.parseInt(f.getText());”时,我收到了一个错误“无法将值分配给final变量”。如果我从声明中删除单词"final",并将其作为“int c”进行定义,则在同一行上我会收到一个错误“无法从类内部访问局部变量c;需要声明为final”。有人能告诉我这是为什么吗?