J
jonck
Hi,
I have been struggling with this for days now, but it does not look
like I'm going to figure it out. Here is the situation:
I have a class that stores values that it read in from a database, lets
call this class Storage. I display this data using a JPanel (which I
will call DisplayPanel) with several JTextFields, JComboBoxes, JPanel's
with pictures drawn on them, etc... So in other words, when the user
selects a new record, the DisplayPanel loads in a new Storage class,
and calls all the getters of Storage, something like this:
getFirstNameTextField().setText(storage.getFirstName());
getLastNameTextField().setText(storage.getLastName());
getPicturePanel().drawPicture(storage.getPicture());
etc...
Now this is all fine, but now comes the time when the user has made
some changes and I want to store those back into the Storage class.
I now have to do the same thing again, but this time in reverse:
getStorage().setFirstName(getFirstNameTextField().getText());
getStorage().setLastName(getLastNameTextField().getText());
getStorage().setPicture(getPicturePanel().getPicture());
etc...
Now there are about 20 fields per Storage class and I have about 10
different types of Storage classes, so it seems kind of wasteful, very
non-OOP and error-prone to be doing it as I described above. It seems
like a pointer would be really useful here, so that I could just pass
the pointer as the model value to the view, and then when the view is
updated, the view can update the model, of which it has the pointer.
But since Java is a pass-by-value language this won't work for me.
Does anyone have any suggestions what a better way of doing things
might be in the above described situation?
Thanks, Jonck
I have been struggling with this for days now, but it does not look
like I'm going to figure it out. Here is the situation:
I have a class that stores values that it read in from a database, lets
call this class Storage. I display this data using a JPanel (which I
will call DisplayPanel) with several JTextFields, JComboBoxes, JPanel's
with pictures drawn on them, etc... So in other words, when the user
selects a new record, the DisplayPanel loads in a new Storage class,
and calls all the getters of Storage, something like this:
getFirstNameTextField().setText(storage.getFirstName());
getLastNameTextField().setText(storage.getLastName());
getPicturePanel().drawPicture(storage.getPicture());
etc...
Now this is all fine, but now comes the time when the user has made
some changes and I want to store those back into the Storage class.
I now have to do the same thing again, but this time in reverse:
getStorage().setFirstName(getFirstNameTextField().getText());
getStorage().setLastName(getLastNameTextField().getText());
getStorage().setPicture(getPicturePanel().getPicture());
etc...
Now there are about 20 fields per Storage class and I have about 10
different types of Storage classes, so it seems kind of wasteful, very
non-OOP and error-prone to be doing it as I described above. It seems
like a pointer would be really useful here, so that I could just pass
the pointer as the model value to the view, and then when the view is
updated, the view can update the model, of which it has the pointer.
But since Java is a pass-by-value language this won't work for me.
Does anyone have any suggestions what a better way of doing things
might be in the above described situation?
Thanks, Jonck