2

I've written a lot of Java applications over the years, but the vast majority of them have been simple command line programs with only a few hundred lines and (at most) several classes.

My question is this:

How do I now design/code an interface to this application?? Where do I start? I mean are there any tutorials/resources which describe the steps involved? I know Swing exists, but where do you start, and is it the only option?

Any help/assistance appreciated...

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Donal.Lynch.Msc
  • 3,365
  • 12
  • 48
  • 78
  • 3
    First I think you'll want to decide how you want to deploy the application. If a desktop application, then yes, Swing can work well for you. If it's to be a more distributed application then other ideas might work better (?JSP? but the latter is out of my area of expertise and so I won't give any more specific recommendations for this). If you decide on Swing, then you'll want to check out the [tutorials](http://docs.oracle.com/javase/tutorial/uiswing/components/index.html). – Hovercraft Full Of Eels Jan 13 '12 at 03:43
  • Added the 3 rich client GUI toolkits to the tags. – Andrew Thompson Jan 13 '12 at 04:33
  • [Java Web Start](http://stackoverflow.com/tags/java-web-start/info) is a good deployment option. – trashgod Jan 13 '12 at 05:05

3 Answers3

9

The rich client GUI toolkits for Java are basically:

  • AWT Sun's Abstract Window Toolkit was the original component kit for making GUIs, a toolkit based around using native components. AWT still contains the core of very important parts of J2SE GUIs such as Graphics/Color/Java 2D, Image & BufferedImage, printing, D'n'D..
  • Swing The current, main-stream desktop app. component toolkit. Swing generates the components internally, and allows setting a Pluggable Look and Feel to the GUI. Swing offers components & functionality not available in AWT such as JTable, JTree, support for formatted documents (e.g. RTF & simple HTML) in Swing components.. For more information see things that Swing provides beyond AWT.
  • Java FX 2 Intended as an (eventual) replacement to Swing, AFAIU.
  • SWT is another choice, not written by Oracle, uses natives. I would not recommend it for someone learning rich client programming, since it is a lot easier to get answers in relation to Swing.
Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • I strongly recommend SWT instead of Swing too. Eclipse RCP is still more mature than Swing application framework. And one of the most important reason for me is font rendering of Swing/AWT in Linux is horrible. – wyz Jan 13 '12 at 05:46
  • @wyz Perhaps you need to look into setting the run-time [AA font setting](http://docs.oracle.com/javase/7/docs/technotes/guides/2d/flags.html#aaFonts) or other font related settings. – Andrew Thompson Jan 13 '12 at 08:38
  • @AndrewThompson I have tried various settings. It will improve, and definitely cannot the native rendering. If you could achieve it, please post a snapshot and let me know your settings. I'm more than happy to know the trick. (BTW, font rendering is the main reason from me trying JetBrain products in Linux as I cannot stand the font). – wyz Jan 16 '12 at 02:43
  • *"please post a snapshot"* What good would a snapshot of my Windows 7 machine do? – Andrew Thompson Jan 16 '12 at 02:45
  • @AndrewThompson Font rendering in Windows is acceptable to me. My issue is with Swing in Linux. – wyz Jan 20 '12 at 01:45
5

You have to learn core GUI API java.awt and its sub-packages along with (extended API) javax.swing and its sub-packages. You may start - The Java Tutorial.

KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
  • But ignore the AWT components and use Swing. – Andrew Thompson Jan 13 '12 at 04:14
  • @AndrewThompson - Appreciate! Only few components of AWT, especially Widget components - Label, TextField, Frame, Panel etc should be avoided but not a whole AWT API/events/layout/print/graphics. – KV Prajapati Jan 13 '12 at 04:20
  • 1
    With that clarification, we are in agreement. Swing is heavily based on the non-component parts of AWT packages (and based in small part on/inherited from a few AWT components). – Andrew Thompson Jan 13 '12 at 04:32
2

No, Swing is not the only option but it is where you should start. Swing is the "new and improved" version of some of the GUI objects in java.awt. Most of the Swing objects build off of their AWT counter parts our are completely new. Both Swing and AWT are a part of the core Java API so it would be best to start with the tutorial that AVD linked you to (The Java Tutorial)

  • `JTable`, `JTree`, support for formatted documents in Swing components.. This kind of stuff goes beyond "new & improved", since AWT provides no similar component/functionality. – Andrew Thompson Jan 13 '12 at 04:14