# Importing PSurfaceAWT

**URL:** <https://discourse.processing.org/t/importing-psurfaceawt/39777>\
**Category:** Coding Questions\
**Created:** [November 18, 2022, 2:03pm UTC](https://discourse.processing.org/t/importing-psurfaceawt/39777 "2022-11-18T14:03:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Svedblen](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@Svedblen](https://discourse.processing.org/u/Svedblen)\
**Post date:** [November 18, 2022, 2:03pm UTC](https://discourse.processing.org/t/importing-psurfaceawt/39777/1 "2022-11-18T14:03:28Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [November 18, 2022, 4:34pm UTC](https://discourse.processing.org/t/importing-psurfaceawt/39777/2 "2022-11-18T16:34:29Z")

</div>

Hi @Svedblen,

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

Guess you want s.th. like this…

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

JFrame frame;

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

```

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![Svedblen](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@Svedblen](https://discourse.processing.org/u/Svedblen)\
**Post date:** [November 18, 2022, 6:24pm UTC](https://discourse.processing.org/t/importing-psurfaceawt/39777/3 "2022-11-18T18:24:13Z")

</div>

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. 😊

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [November 18, 2022, 6:55pm UTC](https://discourse.processing.org/t/importing-psurfaceawt/39777/4 "2022-11-18T18:55:56Z")

</div>

Hi @Svedblen,

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

```auto
void setup() {
//...
}

void draw() {
//...
}

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

```

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![NumericPrime](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/numericprime/32/16318_2.png) [@NumericPrime](https://discourse.processing.org/u/NumericPrime)\
**Post date:** [November 20, 2022, 10:38am UTC](https://discourse.processing.org/t/importing-psurfaceawt/39777/5 "2022-11-20T10:38:16Z")

</div>

An alternate solution would be:

```auto
void setup() {
  registerMethod("dispose",this);
}
void draw() {
}
void dispose() {
  println("test");
}

```

---

<div class="post-metadata">

**Author:** ![Svedblen](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@Svedblen](https://discourse.processing.org/u/Svedblen)\
**Post date:** [November 20, 2022, 11:43am UTC](https://discourse.processing.org/t/importing-psurfaceawt/39777/6 "2022-11-20T11:43:00Z")

</div>

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