大型项目的Java GUI架构 [英] Java GUI architecture for larger project

查看:50
本文介绍了大型项目的Java GUI架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个应用程序,它将用作多个服务器的接口. 原因:在默认情况下提供的web iface(我们无法更改)中,我们错过了很少的事情,可以做得更好的事情很少,并且可以肯定的是,某些内容的自动化将使工作变得更容易.

我所拥有的:用于与服务器应用程序的Web界面进行通信的几乎完成的课程.

GUI说明: 对于某种版本的0.1:用户名文本字段,用于选择服务器的单选按钮和一个执行"按钮.然后使用几个(4-12)操作按钮来处理数据,带有结果的2x文本区域,带有一些文本数据的一个标签-我可以进行管理. 然后,我需要查看数据-网格MxN,它将加载数据,预期大小:7-15列,通常为10行或更少,但很少会超过1k(甚至更多),但我不需要全部在这种情况下对用户可见).

我需要什么:只是一个建议. 我希望从一个简单的版本开始(并且我已经在进行此工作,但是我坚持了很多事情-95%的cos和GUI绝对是新手,而5%的cos是Java的新手). 我检查了很多教程,但是它们都很简单.


实际问题:

1)验证.在MVC中,控制器应处理所有用户操作-它是由视图的方法完成的,类似于button.addActionListener(param);. anotherButton.addActionListener(paramp; ...?

1b)我已经看到所有内容都是通过一个(嵌套的)类实现的,该类随后检查了源代码或smth-可以吗?会有很多按钮,等等.

2)当我需要对click/dbl click进行操作时,如何实现数据网格?

4)第一行是标题,其余行应该可以滚动-应该在网格中还是外部(自己的网格):

4a)如何确保标题的大小(宽度)与数据中的大小相同(我不想设置直线大小)

4b)到目前为止,我还无法创建任何可滚动的内容,但是我猜这很糟糕.如何确保标题保留在某个地方,其余部分可以滚动?

5)应如何实施数据更新"?我已经从JPanel中删除了网格组件,然后制作了一个新组件并将数据添加到其中(简单,但是也许还有另一种方法).首要的增强功能之一就是排序-使用与用于新内容相同的方式吗?


非常感谢您提供任何答案,我知道这不是很具体,但是我发现的示例太简单了.

我计划进行很多增强,但是那是将来的事,我不介意重复几次GUI/Controller,至少,我会练习,但是我不想完成代码的一部分并意识到我必须重写控制器的一半和视图的1/4才能实现.

注意:我计划在工作中使用它作为工具(如果一切顺利,只需单击几下即可达到我工作的25-50%:-) 所以我真的是这个意思.

注#2:我对编程并不陌生,但是我从未创建过GUI(这就是为什么我的GUI带有带有2个项目和3个组件的菜单栏,并且几乎完成了web-iface连接)./p>

注意#:3可拖动的数据标题,带标签的数据视图-这就是未来的计划:-)

解决方案

  1. 此处检查了Swing中的MVC;使用嵌套类可以简化原型设计和创建 mcve 来回答以后的问题;根据需要,可以将嵌套类提升为具有 package-private 访问.

  2. 使用 JTable 渲染器的flyweight实现非常适合组织数据按行和列.

  3. 第三个项目不存在,但始终记住

  4. 使用 JScrollPane 使表格标题保持固定.

  5. 更新 TableModel ,然后侦听视图将自动更新以响应.

I want to make an app, which will work as interface to several servers. Why: In web iface provided by default (and we cannot change it) are few things we miss, few could be done better and for sure automation of some stuff would make the job easier.

What do I have: almost finished classes for communication with web interface of a server app.

GUI description: For some kind of version 0.1: text field for username, radio button to select server and one "go" button. Then several (4-12) action buttons to operate on data, 2x text area with results, one label with some text data - I can manage this. Then I need to view the data - grid MxN which will load the data, expected size: 7-15 columns, usually 10 rows or less, but rarely it can go over 1k (or even more, but I don't need all to be visible to the user in that case).

What I need: simply an advice. I wish to start with a simple version (and I'm working on that already, but I'm stuck on too many things - 95% cos and absolutely new to GUI and 5% cos I'm new to java). I've checked many tutorials, but they're all simple.


Real questions:

1) Verify. In MVC controller should handle all user actions - is it done by view's method which is something like button.addActionListener(param); anotherButton.addActionListener(paramp; ...?

1b) I've seen all implemented via one (nested) class, which was then checking source or smth - is that ok? There will be a lots of buttons etc.

2) How to implement the data grid, when I need to take actions on click / dbl click?

4) First row is header, the rest should be scroll able - should it be in the grid or outside (its own grid):

4a) How to make sure header's size (width) will be the same as in data (I don't want to set up straight size)

4b) I failed to create anything scrollable so far, but thats my bad I guess. How to ensure header will hold on a place and the rest can be scrolled?

5) How should be "data update" implemented? I've got JPanel from which I remove grid component and then I make new one and add data into it (simple, but perhapss there is another way). One of first enhancements will be sorting - use the same way I used for new content?


Thanks a lot for any answer, I know this is not very specific, but example I've found are too simple.

I plan a lots of enhancements, but thats in the future and I don't mind to rework GUI/Controller several times, at least, I'll practise, but I don't want to finish one part of the code and realise I've got to rewrite half of a controller and 1/4 of a view to make it possible.

Note: I plan to use this at work as my tool (if things go right, I could make 25-50% of my work by few clicks :-) So I really mean this).

Note#2: I'm not new to programing, but I've never created GUI (which is why I've got GUI with menu bar with 2 items and 3 components and almost done web-iface connections).

Note#:3 dragable data header, tabbed data view - thats the plan for the future :-)

解决方案

  1. MVC in Swing is examined here; use nested classes for ease in prototyping and creating an mcve for future questions; as the need arises, nested classes can be promoted to separate classes having package-private access.

  2. Use JTable; its flyweight implementation of renderers is good for organizing data by row and column.

  3. Item three does not exist, but "always remember to translate cell coordinates" if you plan to drag columns or sort rows.

  4. Use a JScrollPane to keep the table header stationary.

  5. Update the TableModel, and the listening view will update itself in response.

这篇关于大型项目的Java GUI架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆