简体   繁体   English

大型项目的Java GUI架构

[英]Java GUI architecture for larger project

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. 原因:在默认情况下提供的web iface(我们无法更改)中,我们错过了很少的事情,可以做得更好的事情很少,并且可以肯定的是,某些内容的自动化将使工作变得更容易。

What do I have: almost finished classes for communication with web interface of a server app. 我所拥有的:与服务器应用程序的Web界面进行通信的几乎完成的类。

GUI description: For some kind of version 0.1: text field for username, radio button to select server and one "go" button. GUI描述:对于某种版本的0.1:用户名文本字段,用于选择服务器的单选按钮和一个“执行”按钮。 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. 然后使用几个(4-12)操作按钮来处理数据,带有结果的2x文本区域,带有一些文本数据的一个标签-我可以进行管理。 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). 然后,我需要查看数据-网格MxN,它将加载数据,预期大小:7-15列,通常为10行或更少,但很少会超过1k(甚至更多),但我不需要全部在这种情况下对用户可见)。

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). 我希望从一个简单的版本开始(并且我已经在进行此工作,但是我坚持了很多事情-95%的cos和GUI绝对是新手,而5%的cos是Java的新手)。 I've checked many tutorials, but they're all simple. 我检查了许多教程,但是它们都很简单。


Real questions: 实际问题:

1) Verify. 1)验证。 In MVC controller should handle all user actions - is it done by view's method which is something like button.addActionListener(param); 在MVC中,控制器应处理所有用户操作-它是由视图的方法完成的,类似于button.addActionListener(param);。 anotherButton.addActionListener(paramp; ...? anotherButton.addActionListener(paramp; ...?

1b) I've seen all implemented via one (nested) class, which was then checking source or smth - is that ok? 1b)我已经看到所有这些都是通过一个(嵌套的)类实现的,然后检查了源或smth-可以吗? 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? 2)当我需要对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): 4)第一行是标题,其余行应具有滚动能力-应该在网格中还是外部(自己的网格):

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) 4a)如何确保标题的大小(宽度)与数据中的大小相同(我不想设置直线大小)

4b) I failed to create anything scrollable so far, but thats my bad I guess. 4b)到目前为止,我还没有创建任何可滚动的内容,但是我猜那是我的错。 How to ensure header will hold on a place and the rest can be scrolled? 如何确保页眉将保留在某个地方,其余部分可以滚动?

5) How should be "data update" implemented? 5)应该如何实施“数据更新”? 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). 我已经从JPanel中删除了网格组件,然后制作了一个新组件并将数据添加到其中(简单,但是也许还有另一种方法)。 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. 我计划了很多增强功能,但是那是将来的事情,我不介意重复几次GUI / Controller,至少我会练习,但是我不想完成一部分代码并意识到我必须重写控制器的一半和视图的1/4才能实现。

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). 注意:我计划在工作中使用它作为工具(如果一切正常,只需单击几下即可达到我工作的25-50%:-)所以我的意思是这样。

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

Note#:3 dragable data header, tabbed data view - thats the plan for the future :-) 注意#:3可拖动的数据标题,带标签的数据视图-这就是未来的计划:-)

  1. MVC in Swing is examined here ; Swing中的MVC在这里进行了检查; use nested classes for ease in prototyping and creating an mcve for future questions; 使用嵌套类来简化原型设计并为将来的问题创建mcve as the need arises, nested classes can be promoted to separate classes having package-private access. 根据需要,可以将嵌套类提升为具有包私有访问权限的单独类。

  2. Use JTable ; 使用JTable ; its flyweight implementation of renderers is good for organizing data by row and column. 它的渲染器的 flyweight实现非常适合按行和列组织数据。

  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. 使用JScrollPane可使表格标题保持固定。

  5. Update the TableModel , and the listening view will update itself in response. 更新TableModel ,侦听视图将作为响应进行更新。

如果您不仅对事件/消息体系结构感兴趣,还对处理鼠标/键盘输入,悬停检测,小部件,临时菜单,通过小部件对齐来调整大小,拖放等感兴趣,那么我可以建议您看一下通过有用的资源来回答他的问题和我的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM