Java table arraylist modification
Basically it's a task to manage properties, and I am doing a much more complex solution than it is required. It is just the last bit where I struggle.
To give you an idea of what we have:
- Properties (superclass)
- PropertiesToLet(extends Properties)
- PropertiesToSell(extends Properties)
- EstateAgent (GUI to manage the properties)
So the part I am struggling with is basically the EstateAgent class.
What I wrote so far: http://pastebin.com/0qieM67j
That a about 500 lines - But I need help with the theoretical part not the programming part - because I dont want you to do my coursework - I just need the solution how to approach that.
The lines I am struggling with are from: 55 to 113
Its about a table that I create and insert rows into it. Each row represents a property. It could be a propertyToLet or a propertyToSell object. Those properties come from my ArrayList<Property>
properties.
The inserting row and showing the table is fine and it is working the way it should. So there is problem with the code. I apologize for the code structure - but we are limited in the submission - so we cannot submit more than 4 files those file are obviously the named classes - so I cannot extend any more classes or files to the project.
So what I want to do now is开发者_Go百科: Editing a property.
I have the row that represents a property. It is showing me the position in the arrayList and all the values that I can get.
So now there are a few more possibilities.:
- Add and Remove a tenant from a PropertyToLet
- base on a tenant you can collect the rent and pay the rent and see how much rent is left to pay.
- Add and Remove a purchaser from a PropertyToSell (the sold will then change according if there is a purchaser or not)
So basically there are several ways how to continue from here. For instance it could be a behaviour like this:
RightClick on the property opens a context menu where the mouse is and I can choose other options such as: Remove Tenant, Add Tenant, Collect Rent, Show Rent Owed, Add a purchaser, Remove a purchaser ---- ofcourse depending on what kind of property it is.
Double click on a row => edit the property ( have a look at this screenshot)
- it shows a window that I use to add a property - I could add all the values in the field and that button changes to "Update Property"
That would be one solution another one would be: - Edit the cell of the row => changes the value of the property (they will inspect the object and see if that really changed and not just the row value)
That are my ideas of how to inject the last steps of bringing the functionality into the application.
So here are my questions:
And than I need an outside opinion what is easier and faster to implement in this very limited task. The way of opening the existing add window and change it to an edit window - I don't want to have redundant code! Or changing the value by editing the cell so that the values in the arraylist change.
I need some help with the approach what is easier and what is better.
I really appreciate any help here!
I am looking forward to see some answers.
EDIT I finished the popup Menu thank you for your help. I edited the question as wel.
Since jdk5, the recommended way to attach a JPopupMenu to a component is
component.setComponentPopupMenu(menu)
This popup is automatically shown when a user gesture (mouse or keyboard) is interpreted as popup trigger - which may vary across OSs.
As to selecting a row on right (popup-trigger) mouseEvent: it's not done by default in Swing, but seems to be the norm nowadays for (near-)native applications (on vista) - arguably a but in Swing. Volunteers to report, anybody ;-)
精彩评论