Hi,
@glv’s example slightly modified…
Cheers
— mnse
Code
// Display an image without window border and transparent background
// Author: glv
// Date: 2023-10-15
// Insight gleaned from various sources; seek and you shall find.
// slightly modified @mnse ;)
import processing.awt.*;
import java.awt.*;
import javax.swing.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.net.URL;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
ImageIcon img;
BufferedImage bimg;
MouseAndKeyHandler mouseAndKeyHandler; // moving by mouse and exit on ESC key
void setup() {
surface.setVisible(false);
PSurfaceAWT.SmoothCanvas canvas = (PSurfaceAWT.SmoothCanvas) surface.getNative();
JFrame frame = (JFrame) canvas.getFrame();
frame.dispose();
String imgPath = dataPath("hand.gif"); // you can use also an animated gif :)
img = new ImageIcon(imgPath);
frame = new JFrame();
frame.setPreferredSize(new Dimension(img.getIconWidth(), img.getIconHeight()));
frame.add(new JLabel(img));
mouseAndKeyHandler = new MouseAndKeyHandler(frame);
frame.addMouseListener(mouseAndKeyHandler);
frame.addMouseMotionListener(mouseAndKeyHandler);
frame.addKeyListener(mouseAndKeyHandler);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setUndecorated(true);
frame.setBackground(new Color(0, 0, 0, 0));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
class MouseAndKeyHandler implements MouseListener, MouseMotionListener, KeyListener {
JFrame frame;
PVector mouse;
public MouseAndKeyHandler(JFrame f) {
frame=f;
mouse = new PVector();
}
@Override public void mousePressed(MouseEvent e) {
mouse.set(e.getX(), e.getY());
}
@Override public void mouseReleased(MouseEvent e) {
mouse.mult(0);
}
@Override public void mouseDragged(MouseEvent e) {
frame.setLocation(floor(frame.getLocation().x + (e.getX() - mouse.x))
, floor(frame.getLocation().y + (e.getY() - mouse.y)));
}
@Override public void mouseMoved(MouseEvent e) {
}
@Override public void mouseClicked(MouseEvent e) {
}
@Override public void mouseEntered(MouseEvent e) {
}
@Override public void mouseExited(MouseEvent e) {
}
@Override public void keyPressed(KeyEvent e) {
}
@Override public void keyTyped(KeyEvent e) {
}
@Override public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
frame.dispose();
}
}
}
hand.gif (to download, right click and save as):