PDA

View Full Version : Java back with Cocoa front?




Forquare1
Oct 29, 2009, 11:32 AM
Hello all,

Although I've done some Objective-C programming, I'm far more confident in coding in Java.
Is it possible for me to create a GUI using IB, writing the controller in Objective-C, and then linking the controller with a Java model?

I'm planning to code primarily for Snow Leopard (as that is my active platform). I will then look at support on Leopard for potential users who haven't upgraded.

If it is possible, how can I achieve this? Is there some documentation I should read involved in this?

Many thanks,
Ben



lee1210
Oct 29, 2009, 01:06 PM
JNI:
http://en.wikipedia.org/wiki/Java_Native_Interface
http://java.sun.com/docs/books/jni/

You can embed a JVM in your C (or in this case Objective-C) program, and make calls to your java code from C (and vice versa). If you wouldn't mind making the front-end Objective-C++, using JNI is much easier from C++ rather than straight C.

-Lee

EDIT: You will have to be careful not to mix your nomenclature too much. You might get confused about whether that nib is of a cocoa bean or coffee bean. Heaven forbid you want to mix some NUTMEG (http://sai.msu.su/sal/F/2/NUTMEG.html) into this Mochachino you're brewing up.

Forquare1
Oct 30, 2009, 03:50 AM
Many thanks Lee,

I shall look into that over the weekend if time allows.

Many thanks once again,

Ben

Forquare1
Oct 30, 2009, 09:20 AM
I've been reading through the JNI book, and in the first example, I stumbled.

It says to compile a shared library on solaris do this:
cc -G -I/java/include -I/java/include/solaris HelloWorld.c -o libHelloWorld.so

However, I'm on OS X...How can I achieve the same thing? (In XCode or on the command line)

Many thanks,
Ben

wrldwzrd89
Oct 30, 2009, 09:58 AM
I've been reading through the JNI book, and in the first example, I stumbled.

It says to compile a shared library on solaris do this:
cc -G -I/java/include -I/java/include/solaris HelloWorld.c -o libHelloWorld.so

However, I'm on OS X...How can I achieve the same thing? (In XCode or on the command line)

Many thanks,
Ben
The command line options are almost identical, but the folders where the the needed include files live are different. I don't think this can be done with the XCode GUI, at least in Snow Leopard, due to XCode's lack of Java support. I'd tell you where the include folders are, but I'm not at a Mac (let alone have access to Xcode). :o

chown33
Oct 30, 2009, 01:00 PM
I don't think this can be done with the XCode GUI, at least in Snow Leopard, due to XCode's lack of Java support.

Xcode 3.2 has Java project templates in its Organizer window. Open the Organizer window, click the + icon below the list, and see the available templates.

Like many things in Xcode 3.2, it's not in the same place as before. For example, there used to be a control to get the detailed build log (aka build transcript). Here's the new way:
http://lists.apple.com/archives/xcode-users/2009/Oct/msg00624.html

There's a "JNI" section heading here:
http://developer.apple.com/mac/library/documentation/Java/Conceptual/Java14Development/05-CoreJavaAPIs/CoreJavaAPIs.html

Also see:
http://developer.apple.com/mac/library/technotes/tn2005/tn2147.html

Forquare1
Oct 30, 2009, 02:50 PM
Xcode 3.2 has Java project templates in its Organizer window. Open the Organizer window, click the + icon below the list, and see the available templates.

Like many things in Xcode 3.2, it's not in the same place as before. For example, there used to be a control to get the detailed build log (aka build transcript). Here's the new way:
http://lists.apple.com/archives/xcode-users/2009/Oct/msg00624.html

There's a "JNI" section heading here:
http://developer.apple.com/mac/library/documentation/Java/Conceptual/Java14Development/05-CoreJavaAPIs/CoreJavaAPIs.html

Also see:
http://developer.apple.com/mac/library/technotes/tn2005/tn2147.html

Cheers for that, I did wander where Java had disappears to...

Oddly enough, there is a huge difference between XCode 3.2 and XCode 3.2.1, I have the two versions on my MacBook and Mac Pro and they are fairly different in layout...

As to compiling a C file into a library, I'm still not sure, I've searched the web, but I'm obviously asking a stupid question or looking for the wrong thing...:(

chown33
Oct 30, 2009, 06:20 PM
As to compiling a C file into a library, I'm still not sure, I've searched the web, but I'm obviously asking a stupid question or looking for the wrong thing...:(

Under the "JNI" section heading here:
http://developer.apple.com/mac/library/documentation/Java/Conceptual/Java14Development/05-CoreJavaAPIs/CoreJavaAPIs.html

there are examples of actual command-line compilation of JNI library source. That's why I posted that URL before.

If those examples don't work or don't meet your needs, be specific about how they don't work or don't meet your needs. That includes posting any error messages, rather than just saying "It doesn't work" or "It has an error".

Forquare1
Oct 30, 2009, 06:43 PM
Under the "JNI" section heading here:
http://developer.apple.com/mac/library/documentation/Java/Conceptual/Java14Development/05-CoreJavaAPIs/CoreJavaAPIs.html

there are examples of actual command-line compilation of JNI library source. That's why I posted that URL before.

If those examples don't work or don't meet your needs, be specific about how they don't work or don't meet your needs. That includes posting any error messages, rather than just saying "It doesn't work" or "It has an error".

Aha! I'm sorry chown33, my internet is playing up and I didn't see your last two links before as only parts of the page loaded.
You link help's me very much.

Thanks you all for all your help :)
Ben

Nordwolf
Oct 30, 2009, 09:14 PM
Why not just do the whole application in Java + Swing if you want to use Java? The Swing look and feel in Apple's latest versions of Java is practically indistinguishable from a native Cocoa application. This would be a lot less error prone than trying to use JNI. And the Java-Cocoa bridge is deprecated, so I would not suggest using that either.

Take a look at some of the latest screen shots of NetBeans on Mac for example to see how good the look and feel has gotten. Here's a link to one: http://blogs.sun.com/stan/resource/laf/nbdev.png

ranguvar
Oct 31, 2009, 05:24 AM
You might want to take a look at Ken Orr's blog (http://explodingpixels.wordpress.com/). He creates custom controls / views using Swing that you can then implement in your Java app. If you stick to his widgets and Swing's native-looking components, your application will look virtually undistinguishable from a native Cocoa app.

elppa
Oct 31, 2009, 08:53 AM
Take a look at some of the latest screen shots of NetBeans on Mac for example to see how good the look and feel has gotten. Here's a link to one: http://blogs.sun.com/stan/resource/laf/nbdev.png

One problem is the “unified toolbar” in NB looks like a unified toolbar but doesn't behave like unified toolbar. This is a retrograde step in my opinion because at least in previous versions the draggable area was clear.

ranguvar
Nov 3, 2009, 10:04 AM
One problem is the “unified toolbar” in NB looks like a unified toolbar but doesn't behave like unified toolbar. This is a retrograde step in my opinion because at least in previous versions the draggable area was clear.

Again, let me point you to Ken Orr's blog (http://explodingpixels.wordpress.com/) and his Mac Widgets.
His unified toolbar looks & behaves exactly like a native unified toolbar.