简体   繁体   中英

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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