Java tutorial
import java.awt.Color; import java.awt.GraphicsDevice; import java.awt.GraphicsDevice.WindowTranslucency; import java.awt.GraphicsEnvironment; import java.awt.Polygon; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import javax.swing.JButton; import javax.swing.JFrame; public class Test { public static void main(String[] args) { GraphicsEnvironment envmt = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice device = envmt.getDefaultScreenDevice(); if (!device.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSLUCENT)) { System.out.println("Shaped windows are not supported on" + "your system."); System.exit(0); } ApplicationWindow window = new ApplicationWindow(); window.setVisible(true); } } class ApplicationWindow extends JFrame { public ApplicationWindow() { this.setSize(300, 300); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.add(new JButton("asdf")); final Polygon myShape = getPolygon(); this.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { setShape(myShape); ((JFrame) e.getSource()).setForeground(Color.red); ((JFrame) e.getSource()).setBackground(Color.red); } }); this.setUndecorated(true); } private Polygon getPolygon() { int x1Points[] = { 0, 20, 100, 200, 330, 300, 200, 100 }; int y1Points[] = { 100, 200, 310, 300, 200, 100, 10, 0 }; Polygon polygon = new Polygon(); for (int i = 0; i < y1Points.length; i++) { polygon.addPoint(x1Points[i], y1Points[i]); } return polygon; } }