MATLAB BUILDER JA 2 Guide de l'utilisateur Page 31

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 292
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 30
Understanding the Magic Square Example
Understanding the Magic Square Example
The Magic Square example shows the following aspects of writing an
application using components created by MATLAB Builder for Java:
“Importing Classes” on page 1-23
“Creating an Instance of the Class” on page 1-23
“Calling Class Methods from Java” on page 1-23
Importing Classes
You must import the MATLAB libraries and your own Java classes into your
code. Use the Java
import function to do this.
For the
magicsquare example, the following statements perform the
necessary actions:
import com.mathworks.toolbox.javabuilder.*;
import magicsquare.*;
Creating an Instance of the Class
As with all Java classes, you must use the new function to create an instance
of a class. To create an object (
theMagic)fromthemagic class, the example
applicat ion uses the following code:
theMagic = new magic();
Calling Class Methods from Java
Once you have instantiated the class, you can call a class method as you do
with any Java object. In the Magic Square example, the
makesqr method is
called as show n:
result = theMagic.makesqr(1, n);
1-23
Vue de la page 30
1 2 ... 26 27 28 29 30 31 32 33 34 35 36 ... 291 292

Commentaires sur ces manuels

Pas de commentaire