Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

addActionListener problem...

 
Rocky Summers
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
i'm having trouble with ActionListener...
i'm doing a registration form. this is my code for a bunch of textfields:

and after that, i have the submit button:

All i just wanted to know is how to determine if user has inputted something in the textfield.
The error in that chunk of code is:

Is there any way of not making the txtfield[] a final and getting around it?
Thank you for your time.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, two ways to deal with this. One would be to make the textfield array a member variable rather than a local variable -- then it doesn't need to be final. The code would hardly change at all -- just move the declaration up to class scope.
The other way is just to make the existing variable final, as the compiler suggests. Making the array reference final does not prevent you from modifying the contents -- it only prevents you from allocating a new array altogether, something you likely don't need to do. Try it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic