Best way to capture input.

A

Aaron Fude

Hi,

I am building a gui in which the user has to (just for an example)
enter personal data. As one of the inputs, the user needs to choose
people he knows from a list. A list (in a modal window) pops up when a
user clicks the button "choose". Then the user picks his contacts from
a list and clicks OK. The modal window closes and another entry in the
main window now contains the list of people selected.

I see one strategy to implement this. It is to attach a listener to
the OK button and when it's clicked the list of selected people is
transfered to the main window. Easy enough.

But could one make an alternative approach work. Is it possible to use
code that looks like this:

Vector<Person> people = chooseFromTheList();

where chooseFromTheList() opens the modal dialog, waits for user to
make the selection and click OK and then actually returns the vector
of selected people.

I hope I was able to formulate my question in a sensible way.
 
E

Eric Sosman

Aaron said:
Hi,

I am building a gui in which the user has to (just for an example)
enter personal data. As one of the inputs, the user needs to choose
people he knows from a list. A list (in a modal window) pops up when a
user clicks the button "choose". Then the user picks his contacts from
a list and clicks OK. The modal window closes and another entry in the
main window now contains the list of people selected.

I see one strategy to implement this. It is to attach a listener to
the OK button and when it's clicked the list of selected people is
transfered to the main window. Easy enough.

But could one make an alternative approach work. Is it possible to use
code that looks like this:

Vector<Person> people = chooseFromTheList();

where chooseFromTheList() opens the modal dialog, waits for user to
make the selection and click OK and then actually returns the vector
of selected people.

I hope I was able to formulate my question in a sensible way.

Yes, you could do it this way. The conventional wisdom
is to use a model-and-view architecture, but that's not the
only possible architecture. Sometimes expediency trumps
flexibility.
 
L

Lew

Don't use Vector. Use a "real" List implementation.

Do you need the List to be synchronized? Do you need the extra
non-collections methods?

It's been nearly eleven years since Vector has been obsolete.
 
D

David Segall

Aaron Fude said:
Hi,

I am building a gui in which the user has to (just for an example)
enter personal data. As one of the inputs, the user needs to choose
people he knows from a list. A list (in a modal window) pops up when a
user clicks the button "choose". Then the user picks his contacts from
a list and clicks OK. The modal window closes and another entry in the
main window now contains the list of people selected.
My first thought was "Why doesn't he use a standard Add Remove List?"
<http://java.sun.com/products/jlf/at/book/Idioms6.html>. The answer, I
was surprised to find, is that one is not supplied with Swing. I have
used them with JSF but I could not find a ready-made Swing
implementation.
 
A

Aaron Fude

Don't use Vector.  Use a "real" List implementation.

Do you need the List to be synchronized?  Do you need the extra
non-collections methods?

It's been nearly eleven years since Vector has been obsolete.

I use Vector because I think that ArrayList is a a very ugly name for
a class. If I could use "List" or "typedef Lyst ArrayList" then I
would switch. I know it's a silly reason, but I can't stand the word
"ArrayList".
 
L

Lew

Aaron said:
I use Vector because I think that ArrayList is a a very ugly name for
a class. If I could use "List" or "typedef Lyst ArrayList" then I
would switch. I know it's a silly reason, but I can't stand the word
"ArrayList".

It's a very, very silly reason. It has no basis in engineering. You are
using synchronized methods unnecessarily, and pulling in methods and classes
like Enumeration which are not needed and do not fit in the collections
framework. Anyway, you should declare the variable List, not ArrayList, so
that you can pick the List implementation with the desired performance
characteristics.

I would not want you writing software for me if you choose classes based on
some ridiculous assessment of how "ugly" a name is instead of how well the
construct *actually works*. Sheesh!
 
A

Arne Vajhøj

Aaron said:
I use Vector because I think that ArrayList is a a very ugly name for
a class. If I could use "List" or "typedef Lyst ArrayList" then I
would switch. I know it's a silly reason, but I can't stand the word
"ArrayList".

It is silly - functionality should matter - not the name.

And the name seems consistent with that there also is a
LinkedList class.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top