SCJP 5, SCWCD 5, SCBCD 5
SCJP 5, SCWCD 5, SCBCD 5
Jonathan Elkharrat wrote:even a string array have to assume a certain order..
SCJP 5, SCWCD 5, SCBCD 5
Jonathan Elkharrat wrote:i don't really have to use static part in the application
Jonathan Elkharrat wrote:do you think it's a good way to go or the assessor would judge this as a "too complicated solution"?
Roel De Nijs wrote:
Maybe I'm missing something, but when you have the input field to enter the name of a hotel (or contractor) you will have code like map.put("name", userValue);, so that's static to me (I used something similar: room.setName(userValue);).
Roel De Nijs wrote:
I know a JTable uses MVC, but you still would have a static part there too: the order of columns can be different from the order in your database file, so in your custom table model you would have something like: if columnIndex is 0, return map.get("name");.
Roel De Nijs wrote:
The properties in my value object are of a specific type (e.g. smoking is of type Boolean), so my JTable is able to have specific rendering based on the type (a bit of eye candy). Also using a value object is far more (compile-time) type safe than using a map with some strings as keys.
SCJP 5, SCWCD 5, SCBCD 5
Roel De Nijs wrote:
The database file has 3 fields: name, location and size. The Data class can be made 100% dynamic, that's no problem (I did that myself), whether you use maps or arrays make no difference (based on the interface methods I would opt for arrays).
But in your GUI you'll need always some kind of static (fixed) information. When you want to add an input field to search on location, you just have to hard-code that the value from this field is a location (2nd field in your array).
Roel De Nijs wrote:
When the user wants to see [location, name, size] in the JTable you have to hard-code that again. In the 1st column of your JTable (index = 0) you have to show the 2nd element (index = 1) of your array from the Data class. You simply can't do that dynamically.
SCJP 5, SCWCD 5, SCBCD 5
Jonathan Elkharrat wrote:as i said, i abandonned this way.
Jonathan Elkharrat wrote:(maybe i'll add a function to convert from/parse to an array)
but this way require extensive use of If's and Switch's
Roel De Nijs wrote:
Jonathan Elkharrat wrote:(maybe i'll add a function to convert from/parse to an array)
but this way require extensive use of If's and Switch's
I used also methods to convert a String[] to a value object and vice versa, but no ifs nor switches at all.
Roel De Nijs wrote:
The solution you provided works well as long as the records in your database have to be presented as-is in your JTable. The part you don't understand is the part where that approach won't work If your records in your database are stored as [name, location, size] and you have a functional requirement to present the records in the JTable as [location, name, size] (so when you start the application, records must be shown in that order, without user moving the columns) you need hard-coding.
SCJP 5, SCWCD 5, SCBCD 5
Jonathan Elkharrat wrote:that comment was about the getter/setter way. if i use getter and setter i think i'll have to make some use
of if's and switch's here and there. maybe you're right, i'll have to start and see (i'm must be quick if i want to finish before august 1st)
Jonathan Elkharrat wrote:i still dont understand why can't you do:new Jtable(rooms[][],fieldsName[])
this way the column will have the right names and the getValueAt(i,j) will return rooms[i][j]
SCJP 5, SCWCD 5, SCBCD 5
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |