Technical: Java
Advanced Search
Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

Title



Previous Section Table of Contents Next Section



Making a Double-Clickable Application

Built JarNow that you have successfully built your application, you should see a new file, “SlideShow.jar,” at the same level as your project file (see picture right). This file is the output file created when you perform a make operation on your project. This file contains all of the compiled class files and image resources needed by the application.

This file is a library file; it is not an application. In order to make our application runnable in a convenient format, we need to build a double-clickable Macintosh application. To do so, we need to use a tool called JBindery which is part of the MRJ SDK.

JBinderyIconJBindery is located in the MRJ SDK folder in a folder called JBindery. The application icon is shown above. Launch JBindery by dropping the SlideShow.jar icon on the JBindery icon. (If JBindery doesn’t accept the drop, that means that your desktop database needs to be rebuilt. Double-click on the application icon, and follow the steps carefully to make sure that the setting match). If you need additional information, consult the JBindery Adobe Acrobat documentation file, Using JBindery, located in the same folder as the application.

When JBindery launches, you will see a dialog box with the Command page showing. JBindery Command Dialog

CommandIf the Command page is not visible, click on the Command icon. The first text field labeled “Class name” needs to match our application class that contains the main entry point of the application, the main( ) routine. This field needs to read “SlideShow” since that is our main class.

The additional fields allow us to specify arguments to main (the Optional parameters textfield), and redirect either stdin or stdout (the console).

Since we don’t use these features, we can use the default values for these items.



ClasspathNow click on the Classpath icon in the left column to go to the classpath page. The classpath page contains a panel for adding class files, .jar files, and .zip files that contain resources needed to run the application. The first item $CLASSPATH is the implicit system path where Java classes are located. Any local classes should be placed after this entry.

JBindery Classpath Dialog

As the above shows, our SlideShow.jar needs to be added to the classpath so that our application classes can be found by the class loader. If SlideShow.jar does not appear in this list, you may add it by dragging it from the Finder into the window below the $CLASSPATH line. Since we only have one .jar file for all of our classes, that is the only entry that we need to add. If we had multiple class files or .jar archives, we would want to add all of them here.


AppearanceNow click on the Appearance icon in the left column to go to the appearance page in JBindery.


The only item that needs to be changed is the checkbox that reads Size boxes intrude. Size boxes intrudeThis needs to be checked in order to make our application more Mac-like.



ApplicationLastly, click on the Application icon in the leftmost pane. Here, we will edit the settings that will be used by the double-clickable application. We set the 4-character creator code of the application, minimum and maximum application heap sizes, and specify the resource file to be used.

JBindery Application Dialog
Type “SlyD” in the creator field. Minimum and Maximum heap sizes can be left at their default values.

Drag the file “SlideShow.rsrc” from the Sources (skeleton) folder in the Finder to the rectangular area below the Merge resources from checkbox. When this is successfully completed, you should see the full path of the resource file in the non-editable text field.

This resource file has been pre-created for your convenience to include common Macintosh resource types such as a version resource. We have also added two resource types that you may wish to consider using in your own applications.

MENU Resource The first is a 'MENU' resource. We add a 'MENU' resource with an ID of 1128 with an Apple icon as the menu, and About SlideShow… as the sole menu item. By using this special ID, and registering our about handler, MRJ knows to insert this resource as the first menu item in the Apple Menu. Our menu handler is called when this item is chosen. This also removes the default Quit menu item from the Apple Menu, which is not preferred for finished Macintosh applications.

It is important that the menu is created in exactly this manner, or it will not work correctly. Additional information is provided in the Adobe Acrobat Document About MRJ Toolkit that ships as part of the MRJ SDK.

The other main resource we added to the resource file was a 'BNDL' resource. This resource tells the Finder what icons to use for the application and associated files. It also tells the Finder what type of files your application can accept for drag and drop.

BNDL ResourceThe image (left) shows the 'BNDL' resource in ResEdit. We specify the signature (which is needs to be the same as the creator we specified in the Application pane in JBindery). Our bundle supports three different types. The APPL type is our application, and we specify the 1-bit, 4-bit, and 8-bit small and large icons to be used. The '****' entry specifies that we can handle any file type (we don’t create this type, so we didn’t specify a custom icon), and the 'fold' item specifies that we can accept folders. As you recall, our OpenDocument handler knows how to deal with folders and files.

Now that we have looked at the resources and specified the resource file to be used in JBindery, we can build the application. Click on the Save Settings… button and save the application in the same location as your project file using the name “SlideShow”.

A double-clickable application will be created and should have the icons we specified. That’s it! Congratulations! You have made your first real Java-based application. Feel free to launch your application and drop some image files on it to see how it works.


Back to top



Previous Section Table of Contents Next Section



[an error occurred while processing this directive]