Link to home
Start Free TrialLog in
Avatar of k41d3n
k41d3n

asked on

Collection for a GUI that can be operated on

I'm looking on some advice, perhaps a point in the right direction.

I want to be able to have a window pop up for the user that allows them to add IP addresses to a collection.

Once the IP's are in the collection, then they should be able to check a box to make it an active IP.

What is the best way to go about doing this?

I'd like it to remember their settings for the next time they open the application.

So I am guessing the collection should have:

ip, active

But this method also has to allow expansion in the future in the event that I want to add more data items.

They also need to be able to remove the IP's as well.

What would be an optimal method?

I could create an object for each ip, then add the object to a hash. Operating on single ip's would be a pain though as I would have to iterate through the whole hash just to edit or remove the single object.

Suggestions welcome.

Thanks in advance.
Avatar of Javatm
Javatm
Flag of Singapore image

> What is the best way to go about doing this?

If I where to simulate your thought I will :

1. Create a main window w/ menu's and a JTable.
2. A button for adding an IP Address.
3. Then once the button has been clicked
4. I'll create a JDialog which will ask for the IP Address.
5. Once the user added the IP Address on the JDialog he
    can press an Accept button.
6. Then that will reflect to the JTable.
7. There should be a JCheckbox so that the user can click it to
    make it active.
8. You can choose to add it to a database or create a file for it.
9. To remember what the user did I can create a property file or just
    any file and output a word selected or deselected if the user activates
    a IP Address then my program will read the file everytime the user
    opens the program and that way my app will remember what the
    user did.

Hope that helps . . .
Javatm
Avatar of zzynx
>> I'd like it to remember their settings for the next time they open the application.
Serialization of your collection is the way to go
Serializing an Object: http://javaalmanac.com/egs/java.io/SerializeObj.html
Deserializing an Object: http://javaalmanac.com/egs/java.io/DeserializeObj.html

>> So I am guessing the collection should have:
>> ip, active
I would go for:  (the String representation of) the ip address as the key of the hash map
                         and the IP object as the value

>> But this method also has to allow expansion in the future in the event that I want to add more data items.
Then you simply add more fields to the IP class

>> They also need to be able to remove the IP's as well.
Easy.  
String key = ...; // the String representation of the IP address you want to remove
yourMap.remove(key);

>> I could create an object for each ip, then add the object to a hash.
Indeed.

>> Operating on single ip's would be a pain though as I would have to iterate through the whole hash just to edit or remove the single object.
No you don't.
String key = ...; // the String representation of the IP address you want to edit
IP ip = (IP) yourHashMap.get(key);
ip.setWhateverField(100);
> Serialization of your collection is the way to go
Thats another state for doing it. :)
Another way would be to have a small db encapsulated, such as HsqlDb, which would scale well and be fast
Avatar of k41d3n
k41d3n

ASKER

zzynx,

Help me understand the process of serialization.

I have a IP class that implements Serializable, for each IP the user indicates, I create an IP object, then add it to a hash, is the hash serialized as well?

I guess my question is:, when I serialize, when I am deserializing, how do I know which item I am accessing?

am i serializing the hash, then deserializing the hash and accessing the IP?

Thanks,

ASKER CERTIFIED SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> You just serialize/deserialize the HashMap object.
That means including all keys and values (being your serializable (!) IP objects)
Avatar of k41d3n

ASKER

Bingo. I will do this now. Thanks!
Thanks