User`s guide

1 Getting Started
8 Access the component in a Java application. The sample application for this
example is in
MagicSquareExample\MagicDemoJavaApp\getmagic.java.
getmagic.java
/* getmagic.java
* This file is used as an example for the MATLAB
* Builder for Java product.
*
* Copyright 2001-2006 The MathWorks, Inc.
*/
/* Necessary package imports */
import com.mathworks.toolbox.javabuilder.*;
import magicsquare.*;
/*
* getmagic class computes a magic square of order N. The
* positive integer N is passed on the command line.
*/
class getmagic
{
public static void main(String[] args)
{
MWNumericArray n = null; /* Stores input value */
Object[] result = null; /* Stores the result */
magic theMagic = null; /* Stores magic class instance */
try
{
/* If no input, exit */
if (args.length == 0)
{
System.out.println("Error: must input a positive integer");
return;
}
/* Convert and print input value*/
n = new MWNumericArray(Double.valueOf(args[0]),MWClassID.DOUBLE);
1-18