Hallo, ich versuche ein AWT Image mit dem SWT framework anzuzeigen.
Wenn ich das ganze laufen lasse wirft Java folgende exception:
Kann mir jemand damit helfen? Hier der code:
Wenn ich das ganze laufen lasse wirft Java folgende exception:
Code:
Exception in thread "main" java.lang.IllegalArgumentException: Argument not valid [peer not created]
at org.eclipse.swt.SWT.error(SWT.java:3358)
at org.eclipse.swt.awt.SWT_AWT.new_Shell(SWT_AWT.java:263)
at SurfPeaks.main(SurfPeaks.java:18)
Kann mir jemand damit helfen? Hier der code:
Code:
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.awt.SWT_AWT;
public class SurfPeaks
{
public static void main(String args[])
{
Display display = new Display();
Shell shell = SWT_AWT.new_Shell(display, new SurfImage());
shell.setLayout( new RowLayout());
shell.pack();
shell.open();
while( !shell.isDisposed())
{
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Code:
import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Image;
import com.mathworks.toolbox.javabuilder.Images;
import com.mathworks.toolbox.javabuilder.MWArray;
import com.mathworks.toolbox.javabuilder.MWNumericArray;
import com.mathworks.toolbox.javabuilder.MWException;
import com.mathworks.deploy.peaks.Peaks;
public class SurfImage extends Canvas
{
//This method is basically our "business logic" method.
//It is responsible for instantiating our MATLAB deployment,
//passing in any needed inputs, and dealing with any outputs.
//In this example we have no inputs, and the only output is the
//figure in hardcopy format (three dimensional MWNumericArray).
private static Image getSurfImage()
{
try
{
//Our deployment uses native resources and
//should be disposed of as soon as possible.
Peaks matlabModel = new Peaks();
try
{
//If we had any inputs to our method
//they would be passed in here.
Object[] results = matlabModel.getSurfsFigure(1);
//This array uses native resources and
//should be disposed of as soon as possible.
MWArray mwArray = (MWArray)results[0];
try
{
//Since we want this method to return only
// non MATLAB data
// we convert the MATLAB figure to a
// buffered image and return it.
return Images.renderArrayData
((MWNumericArray)mwArray);
}
finally
{
MWArray.disposeArray(mwArray);
}
}
finally
{
matlabModel.dispose();
}
}
catch(MWException mwe)
{
mwe.printStackTrace();
return null;
}
}
public void paint(Graphics g) {
g.drawImage(getSurfImage(), 10, 10, null);
}
}