MATLAB BUILDER JA 2 Podręcznik Użytkownika Strona 31

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 292
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 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
Przeglądanie stron 30
1 2 ... 26 27 28 29 30 31 32 33 34 35 36 ... 291 292

Komentarze do niniejszej Instrukcji

Brak uwag