2004-11-24

cocoa-java

I've been learning cocoa-java lately.

Why? Because i've written a jsp/java powered website recently and wanted to write a custom Mac OSX GUI for the administration of the site. Native applications have a quality to the user experience that just cannot be replicated through a web interface.

Fortunately, Apple has given us an awesome set of tools for writing native OSX GUIs with Java as the logic behind the app.

A few links and notes for those learning or wanting to learn cocoa-java:

Apple's Cocoa-Java documentation

Note: Application Kit framework is the API for all the GUI stuff
Note: Foundation framework is the API for all the Apple classes for adapting Obj-C objects to Java

O'Reilly has a Cocoa developer center, with Java tips too

Miscellaneous notes:

* If incorporating third-party jars into your application, you'll probably need to tell X-code to Merge your jars with the main project jar when compiling. This is an option on the build target.

* NSSelector objects can take a few minutes to get the hang of. Obj-C uses selectors when an event is fired to figure out which object and method to call to handle that event. This means, usually, that your controller object registers itself to receive certain events fired either by a specific object or a class of objects.

* I highly recommend putting all the actual data logic and/or database code into a separate java file from the Controller. This will give you the ability to re-use all that logic in a web-app, or a Swing/AWT app if you find you have users not using OSX.

* For some reason, Exceptions thrown in callback functions (those called as a target of a Selector) seem to get swallowed up. In other words, the catch{} block never gets called. (I could just be doing things wrong). so I recommend putting any code that generates exceptions elsewhere if possible.

Well, that's all for now. I'll post up more when I think about it.

No comments: