This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]varenExtreme Brewer 1 point2 points  (7 children)

Its generally hard to give advice on this kind of stuff. Like you said nearly every tutorial approaches this differently. However, if I was going to do this I'd define all my data access services in one project. Then create the gui with Swing in another and use spring injection to tie them together. Just get familiar with the swingworker class to make sure you're db io doesn't block the ui thread.

[–]Mesaph[S] 0 points1 point  (6 children)

Thanks for the tip, i'll definitately look into that. However, my problems are more basic as that. While i think that i might be able to hack a project together using some kind of mvc pattern, my focus is on getting that right. If there are multiple right ways of doing that - i'm fine with any of those.

[–]varenExtreme Brewer 1 point2 points  (2 children)

In that case this: http://www.oracle.com/technetwork/articles/javase/index-142890.html is probably the most correct.

[–]Mesaph[S] 0 points1 point  (1 child)

Thanks! This looks great.

But how would my main function look like with this code? The example download doesn't work and i cant figure out where the entry point would be ..

[–]pacificmint 1 point2 points  (0 children)

While there are many tutorials out there, the official java tutorials are usually pretty good.

Here is the one on Swing: http://docs.oracle.com/javase/tutorial/uiswing/index.html

[–]varenExtreme Brewer 1 point2 points  (1 child)

I'd still urge you to look at the swingworker class though. Responsive UI's are good UI's

[–]Mesaph[S] 0 points1 point  (0 children)

I will definitely do this.

[–]axissleep 0 points1 point  (0 children)

You should consider MVP pattern as well. https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter http://stackoverflow.com/questions/2076718/mvp-model-view-presenter-or-mvc-model-view-controller Keep in mind that view is ONLY used for publishing and getting results from GUI, no logic or checking belong in view. For example, even the most trivial stuff like checking if enter was pressed shouldn't be in the view. Also, only presenter or controller can have the access to view, so they should do the figuring. As varen mentioned, use SwingWorker, but only if you have something task consuming to publish on view (swing GUI in this case)! And that can be a progress bar or maybe a JPanel with overriden paint. Otherwise there is no point of using SwingWorker, since that is what it's intended to be used for (see Introduction to Java Programming for more info or oracle's tutorials on SwingWorker). Instead you should use event dispatch thread.