# Creating detached windows

**URL:** https://discourse.processing.org/t/creating-detached-windows/42987
**Category:** Coding Questions
**Created:** [October 16, 2023, 10:48pm UTC](https://discourse.processing.org/t/creating-detached-windows/42987 "2023-10-16T22:48:33Z")
**Posts on this page:** 1
**Showing post:** 30

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [October 23, 2023, 5:56am UTC](https://discourse.processing.org/t/creating-detached-windows/42987/30 "2023-10-23T05:56:55Z")

</div>

This version has been behaving pretty well on a Linux operating system (PopOS). Please see how it runs on your system:

```auto
import java.awt.*;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

Window wnd;
Window wnd1;

class Window extends PApplet {
  Frame frame;
  Canvas canvas;

  Point offset = new Point();

  int x, y, w, h;
  color bkgrnd;

  public Window(int x, int y, int w, int h, color bkgrnd) {
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
    this.bkgrnd = bkgrnd;

    PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
    frame = ((processing.awt.PSurfaceAWT.SmoothCanvas) surface.getNative()).getFrame();
    canvas = (processing.awt.PSurfaceAWT.SmoothCanvas) surface.getNative();
    println(canvas);
    frame.removeNotify();
    frame.setUndecorated(true);
    frame.addNotify();
    frame.setLocation(x, y);
    // canvas.setLocation(0, 28);

    canvas.addMouseListener(new MouseAdapter() {
      void mousePressed(MouseEvent e) {
        offset.x = e.getX();
        offset.y = e.getY();
      }
    }
    );

    canvas.addMouseMotionListener(new MouseMotionAdapter() {
      void mouseDragged(MouseEvent e) {
        Point pt = frame.getLocation();
        frame.setLocation(pt.x + e.getX() - offset.x, pt.y + e.getY() - offset.y);
      }
    }
    );
  }

  void settings() { // Necessary for PApplet
    println(w, h);
    size(w, h); // Sets canvas size
  }

  void setup() {
    background(bkgrnd);
    frame.setResizable(true);
  }

  void draw() {
    fill(0, 255, 0);
    rect(30, 50, 100, 30, 15);
    fill(0); // text color
    textSize(22.0);
    textAlign(CENTER, CENTER);
    text("myBtn", 30, 50, 100, 30);
  }

  void mousePressed() {
    if ((mouseX >= 30) && (mouseX <= 30 + 100) && (mouseY >= 50) && (mouseY <= 50 + 30)) {
      println("button hit.");
    }
  }
}

// ****Default Window**** //

void setup() {
  size(800, 800);
  surface.setTitle("Default Window");
  wnd = new Window(100, 100, 400, 400, color(255, 255, 0));
  wnd1 = new Window(600, 100, 600, 600, color(0, 0, 255));
}

void draw() {
  fill(255, 0, 0);
  circle(width/2, height/2, 200);
}

void mousePressed() {
  println("mousePressed in default window");
}

```

**Output:**

 ![undecorated](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/d/5/d53aec5114d1be6c37305ee19239854b7a8f7f80.png)

---

_[View the full topic](https://discourse.processing.org/t/creating-detached-windows/42987)._
