Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB Builder JA   

Blocking Execution of a Console Application that Creates Figures

waitForFigures Method

The MATLAB Builder JA product adds a special waitForFigures method to each Java class that it creates. waitForFigures takes no arguments. Your application can call waitForFigures any time during execution.

The purpose of waitForFigures is to block execution of a calling program as long as figures created in encapsulated M-code are displayed. Typically you use waitForFigures when:

When waitForFigures is called, execution of the calling program is blocked if any figures created by the calling object remain open.

Code Fragment: Using waitForFigures to Block Execution of a Console Application

The following example illustrates using waitForFigures from a Java application. The example uses a Java component created by the MATLAB Builder JA product; the object encapsulates M-code that draws a simple plot.

  1. Create a work folder for your source code. In this example, the folder is D:\work\plotdemo.

  2. In this folder, create the following M-file:

    drawplot.m
    
    function drawplot()
        plot(1:10);
    
  3. Use the MATLAB Builder JA product to create a Java component with the following properties:

    Package nameexamples
    Class namePlotter

  4. Create a Java program in a file named runplot.java with the following code:

    import com.mathworks.toolbox.javabuilder.*;
    import examples.Plotter;
    
    public class runplot {
    		public static void main(String[] args) {
    				try {
    						plotter p = new Plotter();
    						try {
    								p.showPlot();
    								p.waitForFigures();
    						}
    						finally {
    							p.dispose();
    						}
    				}
    				catch (MWException e) {
    						e.printStackTrace();
    				}
    		}
    }	
  5. Compile the application with the javac command. For an example, see Testing the Java Component in a Java Application.

    When you run the application, the program displays a plot from 1 to 10 in a MATLAB figure window. The application ends when you dismiss the figure.

      Note   To see what happens without the call to waitForFigures, comment out the call, rebuild the application, and run it. In this case, the figure is drawn and is immediately destroyed as the application exits.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS