This version has been behaving pretty well on a Linux operating system (PopOS). Please see how it runs on your system:
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: