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

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 292
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 48
Creating an Instance of the Class
Creating an Instance of the Class
As with any Java class, you ne ed to instantiate th e classes you create with
MATLAB Builder for Java before you can use them in your p rogram.
Suppose you build a component named
MyComponent with a class named
MyClass. Here is an e xample of creating an instance of the MyClass class:
MyClass ClassInstance = new MyClass();
Code Fragment: Instantiating a Java Class
The following Java code shows how to create an instance of a class that was
built with MATLAB Builder for Java. The application uses a Java class that
encapsulates a MATLAB function,
myprimes.
/*
* usemyclass.java uses myclass
*/
/* Import all com.mathworks.toolbox.javabuilder classes */
import com.mathworks.toolbox.javabuilder.*;
/* Import all com.mycompany.mycomponent classes */
import com.mycompany.mycomponent.*;
/*
* usemyclass class
*/
public class usemyclass
{
/** Constructs a new usemyclass */
public usemyclass()
{
super();
}
/* Returns an array containing the primes between 0 and n */
public double[] getprimes(int n) throws MWException
{
myclass cls = null;
3-3
Przeglądanie stron 48
1 2 ... 44 45 46 47 48 49 50 51 52 53 54 ... 291 292

Komentarze do niniejszej Instrukcji

Brak uwag