exception cannot call getImage() from Thread: AWT-EventQueue-1
ncubukcu
ncubukcu at nc.rr.com
Mon May 1 13:33:00 MDT 2006
Thanks Curtis
I think I got it working now. You are right that my
com.app.lt.CreateImage throws me an image using getImage(). I don't know
any other way of creating an image in visad. Is there a shorter way
to add scalar maps to an image other than what I use below?
.
.
contMap = new ScalarMap( field, Display.IsoContour );
colMap = new ScalarMap( longitude, Display.XAxis );
rowMap = new ScalarMap( latitude, Display.YAxis );
pixMap = new ScalarMap( field, Display.RGB );
DisplayImplJ2D display = new DisplayImplJ2D(" ", 700, 500);
GraphicsModeControl dispGMC = (GraphicsModeControl)
display.getGraphicsModeControl();
dispGMC.setScaleEnable(true);
// Add maps to display
display.addMap( colMap );
display.addMap( rowMap );
display.addMap( pixMap );
display.addMap( contMap );
// Create a data reference and set the FlatField as our data
DataReferenceImpl data_ref = new DataReferenceImpl("data_ref");
data_ref.setData( mapField );
// Add reference to display
display.addReference( data_ref );
return display.getImage();
Thanks again for your help
nihat
Curtis Rueden wrote:
> Hi Nihat,
>
> There are restrictions on calling DisplayImpl.getImage from the AWT
> event thread, because doing so generally results in thread deadlock.
> Instead, try calling getImage from a completely separate thread. E.g.:
>
> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
> new Thread() {
> public void run() {
> com.app.lt.CreateImage imagePr = new com.app.lt.CreateImage();
> try {
> BufferedImage myImage =imagePr.plotImage();
> } catch (RemoteException ex) {
> ex.printStackTrace();
> } catch (VisADException ex) {
> ex.printStackTrace();
> }
> }
> }.start();
> ...
> }
>
> Also, I'm not certain what com.app.lt.CreateImage.plotImage does, but
> from its name, it sounds like it builds or updates a display with
> DataReferenceImpl.setData and such -- is there a reason such a method
> would need to call getImage? If you can avoid the getImage call, you
> can continue using the AWT event thread, if you wish.
>
> -Curtis
>
> ncubukcu wrote:
>
>> Hi
>> I am pretty new to visad and currently exploring its usage for my
>> applications. So far I was able to write some simple applications.
>>
>> I have run into a problem when I tried to call a visad application
>> through and applet's "submit" button on a web site as in the
>> following format:
>>
>> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
>> {
>> Util.invoke(false,false, new Runnable() {
>> public void run() {
>> com.app.lt.CreateImage imagePr = new
>> com.app.lt.CreateImage();
>> try {
>> BufferedImage myImage =imagePr.plotImage();
>> } catch (RemoteException ex) {
>> ex.printStackTrace();
>> } catch (VisADException ex) {
>> ex.printStackTrace();
>> }
>> }
>> });
>> .
>> .
>>
>> the exception I get is;
>>
>> Exception in thread "AWT-EventQueue-1" visad.VisADError: cannot call
>> getImage() from Thread: AWT-EventQueue-1
>> at visad.DisplayImpl.getImage(DisplayImpl.java:2630)
>> at visad.DisplayImpl.getImage(DisplayImpl.java:2614)
>> at com.app.lt.CreateImage.plotImage(CreateImage.java:94)
>>
>> where line 94 has the following code;
>> return display.getImage();
>>
>> and display object is;
>> DisplayImplJ2D display = new DisplayImplJ2D(" ", 700, 500);
>>
>> I looked through old e.mails and it seems like this works for
>> everybody else. It works fine if I run the application by itself.
>> Like I said I am a new user and there maybe much easier way to do
>> this but I just don't know yet. any help is greatly appreciated...
>> thanks in advance..
>> nihat
>
>
>
> ===============================================================================
>
> To unsubscribe visad, visit:
> http://www.unidata.ucar.edu/mailing-list-delete-form.html
> ===============================================================================
>
>
==============================================================================
To unsubscribe visad, visit:
http://www.unidata.ucar.edu/mailing-list-delete-form.html
==============================================================================
More information about the visad
mailing list