The 
Mathematica Journal
Volume 9, Issue 1

Search

In This Issue
Tricks of the Trade
In and Out
Trott's Corner
New Products
New Publications
Calendar
News Bulletins
New Resources
Classifieds

Download This Issue 

About the journal
Editorial Policy
Staff
Submissions
Subscriptions
Advertising
Back Issues
Contact Information

Building User Interfaces Using J/Link
Todd Gayley

Introduction

By some measures, Java is the most popular programming language in the world. It features a vast and ever-growing library of classes for just about anything you would want to do with a computer—everything from image and sound processing to database access to internet protocols to advanced user interfaces. Virtually every new computing technology nowadays shows up first in a Java-language implementation. Now imagine for a moment that all of these Java classes were written in Mathematica instead, so that all the power and functionality they provide was available directly to Mathematica programmers. Would that change the rules about what could be done in Mathematica?

Welcome to J/Link, a product that integrates Mathematica and Java so tightly that it is as if everything in Java was actually written in Mathematica. J/Link lets you load Java classes into Mathematica, create objects of those classes, and call methods on them. You can do this with any Java class, without any modification or preparation whatsoever. And you can do it all from the comfortable, integrated, line-at-a-time development environment provided by Mathematica.

Java is good for many things, and one of its more popular uses is for building platform-independent user interfaces. This makes it an ideal toolkit for a commonly sought capability—creating user interface elements for Mathematica programs. You might want something as simple as a progress bar or a dialog box with a few fields for entering input values, or something as complex as a wizard for leading users through the steps of a long computation. J/Link gives you the full power of Java to build these types of interfaces and more, using just Mathematica code, not Java.

This article presents a quick-start introduction to creating Mathematica user interfaces using J/Link. It can be read and worked through input by input in a single sitting. By the end, you will have been introduced to all the major techniques and you will be ready to create your own interfaces. J/Link includes an extensive User Guide that covers all the information in this article, and much more. You can find it in the Help Browser under the Add-ons category, and you should consult it for more detailed examples and explanations. There are also a number of example programs included with J/Link that demonstrate user interface techniques. These can be found in the <Mathematica directory>/AddOns/JLink/Examples/Part1 directory, and they are discussed in Section 1.3 of the User Guide.

Our focus here is on user interfaces designed to be used in conjunction with the notebook front end. That is, we will be creating Mathematica programs that, when run from a typical Mathematica session, cause dialog boxes or other windows to “pop up” on the screen for the user to interact with. It is also possible to use J/Link to write Java programs that call on Mathematica in the background for computational services. That involves going in the other direction—calling the Mathematica kernel from Java code. Such programs are the subject of the second half of the J/Link User Guide, and we will not be dealing with them in this article.



     
About Mathematica  Download Mathematica Player
Copyright © Wolfram Media, Inc. All rights reserved.