| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB Builder JA |
| Contents | Index |
| Learn more about MATLAB Builder JA |
| On this page… |
|---|
Code Fragment: Using waitForFigures to Block Execution of a Console Application |
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:
There are one or more figures open that were created by a Java component created by the MATLAB Builder JA product.
The method that displays the graphics requires user input before continuing.
The method that calls the figures was called from main() in a console program.
When waitForFigures is called, execution of the calling program is blocked if any figures created by the calling object remain open.
Caution Use care when calling the waitForFigures method. Calling this method from an interactive program like Microsoft® Excel® can hang the application. Call this method only from console-based programs. |
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.
Create a work folder for your source code. In this example, the folder is D:\work\plotdemo.
In this folder, create the following M-file:
drawplot.m
function drawplot()
plot(1:10);
Use the MATLAB Builder JA product to create a Java component with the following properties:
| Package name | examples |
| Class name | Plotter |
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();
}
}
} 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.
![]() | Setting Java Properties | Ensuring Multi-Platform Portability | ![]() |

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 |