package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;

public final class MainPanel extends JPanel {
    public MainPanel() {
        super((LayoutManager) null);
        add(makeLabelIcon());
        setPreferredSize(new Dimension(320, 240));
    }
    private JLabel makeLabelIcon() {
        ImageIcon i = new ImageIcon(getClass().getResource("duke.gif"));
        Dimension d = new Dimension(i.getIconWidth(), i.getIconHeight());
        final BufferedImage image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB);
        Graphics g = image.createGraphics();
        i.paintIcon(null, g, 0, 0);
        g.dispose();
        final JLabel icon = new JLabel(i) {
            @Override public boolean contains(int x, int y) {
                return super.contains(x, y) && ((image.getRGB(x, y) >> 24) & 0xFF) != 0;
            }
        };
        icon.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
        MouseAdapter l = new MouseAdapter() {
            private final transient Point start = new Point();
            private Point loc;
            @Override public void mousePressed(MouseEvent e) {
                start.setLocation(e.getPoint());
            }
            @Override public void mouseDragged(MouseEvent e) {
                loc = icon.getLocation(loc);
                int x = loc.x - start.x + e.getX();
                int y = loc.y - start.y + e.getY();
                icon.setLocation(x, y);
            }
        };
        icon.addMouseListener(l);
        icon.addMouseMotionListener(l);
        icon.setBounds(new Rectangle(22, 22, d.width, d.height));
        return icon;
    }
    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

@@ -155,24 +155,82 @@
 wt.image.*;%0A
+import java.io.IOException;%0Aimport javax.imageio.ImageIO;%0A
 import javax
@@ -329,69 +329,38 @@
 per(
-(LayoutManager) null);%0A        add(makeLabelIcon
+new BorderLayout
 ());%0A
+%0A
         
 setP
@@ -359,433 +359,418 @@
     
-setPre
+Buf
 fer
-r
 ed
-Size(new Dimension(320, 240))
+Image image
 ;%0A    
-%7D%0A
     
-private JLabel makeLabelIcon() %7B%0A        ImageIcon i = new ImageIcon(getClass().getResource(%22duke.gif%22));%0A        Dimension d = new Dimension(i.getIconWidth(), i.getIconHeight());%0A        final BufferedImage image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB);%0A        Graphics g = image.createGraphics();%0A        i.paintIcon(null, g, 
+try %7B%0A            image = ImageIO.read(getClass().getResource(%22duke.gif%22));%0A        %7D catch (IOException ex) %7B%0A            ex.printStackTrace();%0A            return;%0A        %7D%0A        JLabel icon = makeLabelIcon(image);%0A        icon.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));%0A        icon.setSize(icon.getPreferredSize());%0A        icon.setLocation(2
 0, 
+2
 0);%0A
+%0A
         
 g.di
@@ -769,143 +769,142 @@
     
-g.dispose();%0A        final JLabel icon = new JLabel(i) %7B%0A            @Override public boolean contains(int x, int y) %7B%0A        
+JDesktopPane desktop = new JDesktopPane();%0A        desktop.setOpaque(false);%0A        desktop.add(icon);%0A        add(desktop);%0A
         
 retu
@@ -903,89 +903,51 @@
     
-return super.contains(x, y) && ((image.getRGB(x, y) %3E%3E 24) & 0xFF) != 0;%0A        
+setPreferredSize(new Dimension(320, 240));%0A
     
@@ -956,602 +956,566 @@
     
-    %7D;%0A        icon.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));%0A        MouseAdapter l = new MouseAdapter() %7B%0A            private final transient Point start = new Point();%0A            private Point loc;%0A            @Override public void mousePressed(MouseEvent e) %7B%0A                start.setLocation(e.getPoint());%0A            %7D%0A            @Override public void mouseDragged(MouseEvent e) %7B%0A                loc = icon.getLocation(loc);%0A                int x = loc.x - start.x + e.getX();%0A                int y = loc.y - start.y + e.getY();%0A                icon.setLocation(x, y
+private JLabel makeLabelIcon(BufferedImage image) %7B%0A        MouseAdapter handler = new ComponentMoveHandler();%0A        return new JLabel(new ImageIcon(image)) %7B%0A            @Override public boolean contains(int x, int y) %7B%0A                return super.contains(x, y) && ((image.getRGB(x, y) %3E%3E 24) & 0xFF) != 0;%0A            %7D%0A            @Override public void updateUI() %7B%0A                removeMouseListener(handler);%0A                removeMouseMotionListener(handler);%0A                super.updateUI();%0A                //handler = new ComponentMoveHandler(
 );%0A 
@@ -1529,34 +1529,12 @@
     
-%7D%0A
     
-    %7D;%0A        icon.
 addM
@@ -1538,33 +1538,39 @@
 ddMouseListener(
-l
+handler
 );%0A        icon.
@@ -1564,21 +1564,24 @@
         
-icon.
+        
 addMouse
@@ -1595,17 +1595,23 @@
 istener(
-l
+handler
 );%0A     
@@ -1617,85 +1617,23 @@
     
-icon.setBounds(new Rectangle(22, 22, d.width, d.height));%0A        return icon
+    %7D%0A        %7D
 ;%0A  
@@ -2443,8 +2443,402 @@
     %7D%0A%7D%0A
+%0Aclass ComponentMoveHandler extends MouseAdapter %7B%0A    private final Point startPt = new Point();%0A    @Override public void mousePressed(MouseEvent e) %7B%0A        startPt.setLocation(e.getPoint());%0A    %7D%0A    @Override public void mouseDragged(MouseEvent e) %7B%0A        Component c = e.getComponent();%0A        c.setLocation(c.getX() - startPt.x + e.getX(), c.getY() - startPt.y + e.getY());%0A    %7D%0A%7D%0A

use ImageIO.read(...) to get BufferedImage