Importing PSurfaceAWT

Hi!

I’m new to Processing and also to Java (but not to SW otherwise). I’m trying to piece together a WindowAdapter, and eventually an window listener, but have trouble getting this import to work:

import processing.awt.PSurfaceAWT;

It gives me the error message
“No library found for processing.awt.PSurfaceAWT”

What do I need to do to resolve this?
Thanks in advance

EDIT: I have kept on trying, without really knowing what I am doing, when it comes to the imports. I now have this

import java.awt.Frame;
import java.awt.event.;
import processing.awt.
;
import processing.awt.PSurfaceAWT;

And no longer get any error regarding the import statements. But what I really try to do is this, which I got from another topic here on the community forum:

PSurfaceAWT frame = (processing.awt.PSurfaceAWT.SmoothCanvas)getSurface().getNative().getFrame();

This gives the error
“Type mismatch: cannot convert from PSurfaceAWT.SmoothCanvas to PSurfaceAWT”

So I’m stuck again. :slight_smile:

1 Like

Hi @Svedblen,

It will be quite hard if you are not understanding what you are going to do … :slight_smile:

Guess you want s.th. like this…

import javax.swing.*;
import processing.awt.*;

JFrame frame;

void setup() {
    frame=(JFrame) ((PSurfaceAWT.SmoothCanvas)getSurface().getNative()).getFrame();
}

Cheers
— mnse

1 Like

Thanks @mnse! Worked great. I’m now catching the “window closing” event just as I wanted.

I might need to do some studying on the Java framework or whatever you call it. :blush:

Hi @Svedblen,

For normal exit behavior (ESC or window close button) you can just override exit…

void setup() {
//...
}

void draw() {
//...
}

void exit() {
   println("going to exit sketch...");
   super.exit();
}

Cheers
— mnse

2 Likes

An alternate solution would be:

void setup() {
  registerMethod("dispose",this);
}
void draw() {
}
void dispose() {
  println("test");
}
1 Like

Thanks @NumericPrime. As always, there’s more than one way to skin a cat! :grin: