Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes calling a method and changing it Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "calling a method and changing it" Watch "calling a method and changing it" New topic
Author

calling a method and changing it

Nick de Waal
Ranch Hand

Joined: Feb 19, 2012
Posts: 42
Hi all,

I have a method that clears all text fields of a particular GUI
here it is:

simple I know but I am a beginner and I thought I would write this to save me from writing it in different actionPerformed methods where I need the same result,
so I could just call this one.
Now for my question: Is it possible to call this method and somehow manipulate it to clear all text except for the first two?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Depending on your specific needs, both now and what you might need in the future, some options are:

1) Pass a boolean indicating whether to clear those first 2 fields or not. The code to clear them goes in an if statement that checks that boolean.

2) Pass in an explicit list of names of fields to clear. (Or not to clear, if that's smaller/rarer.)

3) Break this method into two methods. One to clear all but the first 2, and the other that clears the first 2 fields and then calls the other method.

And various variations on the above.
Nick de Waal
Ranch Hand

Joined: Feb 19, 2012
Posts: 42
Thank you Jeff,

I chose the 3rd option as I found it placed the least exertion on my brain
but I have copied the other 2 options to try out when I have a little more time.

And it works well for what I need.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: calling a method and changing it
 
Similar Threads
question about inputText, form and submit buttom on page
Error message
problem in reset() function
need help - AJAX
GregorianCalendar