开发者

Java GUIs - Accelerate the learning curve

开发者 https://www.devze.com 2023-03-21 06:38 出处:网络
I\'ll be cranking out my first serious GUI in Java here over the next few weeks / months.This will be my first project in Java where I\'ll hold myself to a very high standard for coding practices and

I'll be cranking out my first serious GUI in Java here over the next few weeks / months. This will be my first project in Java where I'll hold myself to a very high standard for coding practices and results, so I expect the learning process will take some time.

I'd say I'm not q开发者_运维知识库uite a beginner with Java, but more of an intermediate user - getting used to the API, still awkward on a few keywords. I'm comfortable with OOP, mainly through PHP development.

Are there any tips people can think of to help accelerate the learning curve, i.e. "don't do THAT" or "I wish someone had told me this" type of things.

The first one I came across in a few other questions was a null layout manager - apparently, that's shoddy programming and leads to trouble down the line. So, that helps me right away, probably saved a week and a few rewrites right there.

Another was use NetBeans to move around in Swing...but I can't elaborate on that one yet, needs some research.

Are there any other strong recommendations out there?


Are there any other strong recommendations out there?

Also on the general subject of layouts, don't spend time trying to to find the 'right' layout, when a combination of nested layouts will achieve the effect. See the Nested Layout Example for sample code.

Java GUIs - Accelerate the learning curve


You might want to check out the following:

JGoodies has the famous FormLayout and other stuff: http://www.jgoodies.com/

SAF JSR-296 implementation fork: http://kenai.com/projects/bsaf/pages/Home

Apache Commons, especially lang, if you don't use these already, you're on the wrong track: http://commons.apache.org/

Not sure about SwingX right now, but it seems to be worth looking at as well: Does anyone use the "swingx" extensions to Swing?

Java practices, general good stuff: http://www.javapractices.com

You should definitely look into using existing frameworks and tools. It helps to read a lot up front to get a picture instead of delving into writing much yourself. There's almost anything that exists except a library for common translations in desktop apps, e.g. for common actions (menu items).

Edit: Ah and don't forget the SwingWorker...


If you're using Eclipse, you can try WindowBuilder Pro, which is a GUI designer now open source and part of the Eclipse project. The code it generates is extremely readable. Honestly, with this tool, I wouldn't do UI development by hand any longer. It does Swing and SWT, amongst other things. Also has support for many powerful layout managers (including MigLayout!).

Java GUIs - Accelerate the learning curve


Another was use NetBeans to move around in Swing...

I'm not a fan of using an IDE to generate because well, now you are tied to the IDE and you can't move from IDE to IDE.

You are forced to follow the structure of the code they generate. I like to be in full control of the code.


Not specific to UI programming, but I strongly recommend you read Effective Java.


Swing is just a GUI API (and anything related to GUI programming e.g. MVC will be applicable and that topic is well covered in CS literature).

Simply note the following caveat (which actually applies to most GUI systems out there as it hugely simplifies the task of writing such libraries):

It is an 'active sub-system' that has its own dedicated thread. Delve into the threading issues of swing, how to use SwingWorker, etc.

As far as tools, last I checked, NetBeans was the king of the hill in Swing land (but that was pre-ora). If you dislike the tool, do yourself a favor and at least create an example app and observe how the IDE organizes your app for you. There is a boat load of collective knowledge right there.


I like GridBagLayout a lot. Flow and Box Layout are also good to know, and group layout if you have Java 6. The NetBeans IDE has a really intuitive GUI manager, but the way it codes things is a bit strange. The null layout of course has the most flexibility but is not good practice like you said, and besides with these layouts, I doubt you would need any more functionality except in rare cases.

0

精彩评论

暂无评论...
验证码 换一张
取 消