• Post Reply Bookmark Topic Watch Topic
  • New Topic

Vectors Or Hasmap  RSS feed

 
Cyrus Serrano
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

im currently creating a simple GUI app. where a Jtable is used. now within the table there are 5 columns of data to be displayed, i was thinking if i can model the data displayed on that by creating a class.

Now, if do create a class, i dont know which collection to use, a haspmap or a vector. i have ideas on both , but havent decided which one to use.

Can you give some thoughts about this situation.. and may you recommend which may i use.
 
Vladas Razas
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this one:

http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

There are couple of ways you can make table in Swing. You can use default model (data class) which is created by Sun <-Thanks! Also you can create your own model class (it takes more time, but the possibilities are almost endless). Heh, well all of this is probably in the link above.

Regarding containers: Vector is a growable array of objects... You know a[1], a[2] etc. While HashMap is a map: "John"->JohnObject, "Peter"->PeterObject. Anyway I don't use Vector. If I need array like behavior I use ArrayList. Their main difference the latter is not synchronized (but you can synchronize it later).

Regards,
Vladas
 
Cyrus Serrano
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

ive noticed that the data in the sample on the link you've given are already given TableDemo, which is the variable named data of type Object[][].

So correct me if im wrong, the data model then is the model for the data
this includes its operations (add rows, delete rows, etc). And to update the view(JTable) and its contents we can implement event handlers which i think is the TableModelListener. I will therefore create added methods for creating a new row of data, this means adding a new object on variable data and likewise for deleting?

Am I correct on this..
[ February 12, 2007: Message edited by: Cyrus Serrano ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!