Java表数组列表修改
基本上,这是一项管理属性的任务,我正在做一个比所需的更复杂的解决方案。这只是我挣扎的最后一点。
让您了解我们拥有的内容:
- Properties (超类)
- PropertiesToLet(extends Properties)
- PropertiesToSell(extends Properties)
- EstateAgent (管理属性的 GUI)
所以我正在努力解决的部分基本上是 EstateAgent 类。
到目前为止我写的内容: http://pastebin.com/0qieM67j
大约 500 行 - 但我需要帮助理论部分而不是编程部分 - 因为我不想让你做我的课程 - 我只需要解决方案如何解决这个问题。
我正在努力解决的问题来自: 55 到 113
这是关于我创建并向其中插入行的表。每行代表一个属性。它可以是 propertyToLet 或 propertyToSell 对象。这些属性来自我的 ArrayList
插入行并显示表格很好,并且它按应有的方式工作。所以代码有问题。我对代码结构表示歉意 - 但我们在提交方面受到限制 - 所以我们不能提交超过 4 个文件,这些文件显然是指定的类 - 所以我无法将更多的类或文件扩展到项目中。
所以我现在想做的是:编辑属性。
我有代表属性的行。它向我显示了 arrayList 中的位置以及我可以获得的所有值。
所以现在还有更多的可能性。:
- 在 PropertyToLet 中添加和删除租户
- 基于租户,您可以收取租金并支付租金,并查看还需要支付多少租金。
- 从 PropertyToSell 添加和删除购买者(出售的金额将根据是否有购买者而改变)
因此基本上有几种方法可以从这里继续。例如,它可能是这样的行为:
右键单击该属性将打开鼠标所在的上下文菜单,我可以选择其他选项,例如:删除租户、添加租户、收取租金、显示欠租、添加购买者,删除购买者 ---- 当然取决于它是什么类型的财产。
双击一行 =>编辑属性(看看这个屏幕截图)
- 它显示了一个我用来添加属性的窗口- 我可以添加字段中的所有值,并且该按钮更改为“更新属性”
这将是一种解决方案,另一种解决方案是: - 编辑该行的单元格=>更改属性的值(他们将检查对象并查看是否真正更改而不仅仅是行值)
这是我关于如何注入将功能引入应用程序的最后步骤的想法。
所以这是我的问题:
与我需要外部意见相比,在这个非常有限的任务中,什么是更容易、更快地实施的。打开现有添加窗口并将其更改为编辑窗口的方式 - 我不想有多余的代码! 或者通过编辑单元格来更改值,以便数组列表中的值发生变化。
我需要一些帮助来了解什么是更容易的以及什么是更好的方法。
我真的很感谢这里的任何帮助!
我期待看到一些答案。
编辑 我完成了弹出菜单,谢谢您的帮助。我也编辑了这个问题。
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: 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 jdk5 开始,将 JPopupMenu 附加到组件的推荐方法是
当用户手势(鼠标或键盘)被解释为弹出触发器时,会自动显示此弹出窗口 - 这可能因操作系统而异。
至于在右侧(弹出触发)鼠标事件上选择一行:在 Swing 中默认情况下不会这样做,但似乎是当今(近)本机应用程序(在 vista 上)的规范 - 可以说是 Swing 中的一个但是。任何人都可以自愿报告;-)
Since jdk5, the recommended way to attach a JPopupMenu to a component is
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 ;-)