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

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

问题描述

我想做一个应用程序,它可以作为多个服务器的接口.原因:在默认提供的 Web 界面中(我们无法更改它),我们遗漏了很少的东西,很少有可以做得更好的,而且某些东西的自动化肯定会让工作更容易.

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 界面进行通信的课程.

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

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

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).

我需要的是:只是一个建议.我希望从一个简单的版本开始(我已经在努力了,但我被困在太多事情上 - 95% 的 cos 和 GUI 的新手,5% 的 cos 我是 Java 的新手).我查了很多教程,但都很简单.

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.

真正的问题:

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

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) 我已经看到所有通过一个(嵌套)类实现的,然后检查源代码或 smth - 可以吗?会有很多按钮等.

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) 当我需要对 click/dbl click 采取行动时,如何实现数据网格?

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

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

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

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

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) 到目前为止,我未能创建任何可滚动的内容,但我想那是我的坏处.如何确保标题保持在某个位置而其余部分可以滚动?

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)数据更新"应该如何实现?我有 JPanel,我从中删除了网格组件,然后我创建了一个新组件并将数据添加到其中(简单,但也许还有另一种方法).第一个增强功能之一将是排序 - 使用与我用于新内容相同的方式吗?

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.

我计划了很多改进,但那是在未来,我不介意多次返工 GUI/控制器,至少,我会练习,但我不想完成代码的一部分并意识到我必须重写一半的控制器和 1/4 的视图才能使其成为可能.

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.

注意:我打算在工作中使用它作为我的工具(如果一切顺利,我可以通过几次点击完成 25-50% 的工作:-)所以我的意思是这个).

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).

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

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).

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

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

推荐答案

  1. 此处检查 Swing 中的 MVC;使用 嵌套类 以简化原型设计和创建mcve 以备将来使用;根据需要,可以将嵌套类提升为具有 包私有访问.

  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.

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

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

第三条不存在,但永远记得翻译 单元格坐标.

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

使用 JScrollPane 以保持表头固定.

Use a JScrollPane to keep the table header stationary.

更新TableModel,监听视图将更新自身作为响应.

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

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

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