views:

569

answers:

6

Last time I had to deal with Java was 2005 and I forgot almost everything about it since then.

Today I need to build a GUI app on the top of Java. I guess it is better to use one of Scala/Groovy/Clojure languages.

The question is: which of them is better for desktop GUI programming? My program will transform and display a series of jpeg/png files + there will be ~10 dialogs (with tons of options in each with all possible widgets).

The main requirement is compactness: I hate to write a dozen lines of code only to draw a simple frame with a button. My background in GUI is (mostly) Tcl/Tk and GTK+.

Thanks in advance.

+10  A: 

DISCLAIMER: I'm a Clojure programmer. I'm obviously biased.

Of all of those languages, I think Clojure and Groovy are probably the most compact. Scala is a curly-bracket language like Java, so it tends to take up a bit more space. However, it's nowhere near as verbose as Java is, and I think Scala is pretty awesome. I know that Scala has a swing wrapper. I've never done GUI development in Scala, so I can't really say how it feels.

I've done some swing development in Clojure, and it doesn't really take much. Using swing direct from Clojure can be tedious until you write yourself some abstractions, but altogether, swing apps are smaller than the same thing in Java because Clojure code tends to be shorter and more concise than Java code.

Clojure also has some wrappers of sorts to make swing development more Clojury. One of which is clj-swing. I've seen some code written using it, and it's pretty cool, and definitely more concise than direct interop.

Now, I don't know Groovy. I really don't know much of anything about it, but I know it's more compact than Java, so I imagine GUI development would be fairly compact as well.

I think Clojure is a safe bet. With clj-swing, or even directly using the Java GUI toolkits directly is going to be really compact compared to Java, and the ability to build abstractions over non-compact stuff with macros is definitely a huge plus. Clojure has my vote.

Rayne
Personally, I think Clojure is too obscure and immature for production code that may need to be maintained over a long time by many developers (though I don't know if that applies to this project).I'm not saying it's a good/bad language, but it's too different from Java for a Java developer to pick it up easily.
Don
If he has the option of these languages at work, obviously, they don't feel it's too "obscure and immature for production code." I think you should let him decide, since it's his application. Beyond that, I know of several companies that use Clojure as their/one of their primary languages, and are proud of it.
Rayne
+3  A: 

I am currently developing an SWT application in Scala and quite like it. But I do expect Clojure would be even more compact.

Alexey Romanov
+8  A: 

Scala comes with fairly complete sample applications for basic GUI elements, which you can run by typing scala scala.swing.test.UIDemo at the command line. You can browse the source code for them here.

You may also look at this document to get an idea of the design principles behind Scala's Swing wrappers.

Daniel
A) Thanks for the little easter egg about the UI demo. I had no idea that existed. Is the source for that available?B) I started using the Scala swing wrappers this weekend after about five years of standard Java swing experience. There's more than a bit of learning curve; it might be easier if you're new to GUI programming. I'll be making a blog post soon highlighting some of the differences.
I82Much
@I82Much The answer has a link to the source code. It should also come with standard Scala distributions -- which include source code for compiler and libraries -- and may be obtained as well with git and subversion.
Daniel
@I82Much Also, I'd love to see that blog post. I think Scala lacks in blog posts about GUI programming.
Daniel
I'm making a minesweeper clone in Scala. Almost finished. When it's in a releasable form I'll put a link here in the comments.
I82Much
+4  A: 

Groovy has the Griffon framework which uses convention over configuration for building GUI apps on the JVM. It's similar to grails/rails but for a rich GUI rather than a web app.

Ted Naleid
I don't know mutch about griffon but didn't day say that they want to have wrappers for jruby and clojure? Remember hearing something like that.
nickik
+3  A: 

I've been writing a GUI by using Clojure directly with Swing. It has worked very well indeed so far. I've also written some custom UI components in Java that have proved very easy to integrate with the Clojure part of the code base.

I also think that clj-swing looks great - possibly easier than using Swing directly if you don't have prior Swing experience.

mikera
+1  A: 

Groovy has something called the swing builder for making GUI programming easier. Here is a piece of sample code from the groovy website, it creates a frame with a button and counts the number of times you click it:

int count = 0
new SwingBuilder().edt {
  frame(title:'Frame', size:[300,300], show: true) {
    borderLayout()
    textlabel = label(text:"Click the button!", constraints: BL.NORTH)
    button(text:'Click Me',
         actionPerformed: {count++; textlabel.text = "Clicked ${count} time(s)."; println "clicked"},
         constraints:BL.SOUTH)
  }
}
Blacktiger