public static void main(String[] args) {
JFrame frame = new JFrame();
JDesktopPane desktopPane = new JDesktopPane();
frame.setContentPane(desktopPane);
for(int i = 0; i < 8; i++) {
JPanel panel = new JPanel();
panel.setBackground(Color.blue);
panel.setSize(100, 100);
DragHandler handler = new DragHandler(panel);
desktopPane.add(panel);
}
frame.pack();
frame.setVisible(true);
}
static class DragHandler extends MouseInputAdapter {
int x0, y0, x, y;
JComponent comp;
Rectangle rw = new Rectangle();
public DragHandler(JComponent comp) {
this.comp = comp;
comp.addMouseListener(this);
comp.addMouseMotionListener(this);
}
public void mousePressed(MouseEvent e) {
x = e.getX();
y = e.getY();
Point p = new Point(x, y);
SwingUtilities.convertPointToScreen(p, e.getComponent());
x = p.x;
y = p.y;
x0 = comp.getX();
y0 = comp.getY();
}
public void mouseReleased(MouseEvent e) {
}
public void mouseDragged(MouseEvent e) {
Point p = e.getPoint();
SwingUtilities.convertPointToScreen(p, e.getComponent());
int dx = x - p.x;
int dy = y - p.y;
rw = comp.getBounds(rw);
rw.x = x0 - dx;
rw.y = y0 - dy;
comp.setLocation(rw.x, rw.y);
}
}
--
____________
http://reader.imagero.com the best java image reader.
> Yes
>
[quoted text clipped - 7 lines]
> >
> > http://reader.imagero.com the best java image reader.
RayL - 07 Jan 2004 11:26 GMT
I'm going to try to play with this today.
Thank you very much.
Ray
> public static void main(String[] args) {
> JFrame frame = new JFrame();
[quoted text clipped - 69 lines]
>>>
>>>http://reader.imagero.com the best java image reader.