frame.setSize(new Dimension(500,500));
//frame.pack();
frame.setVisible(true);
final JButton btn = new JButton("Obj A");
btn.addMouseMotionListener(new MouseMotionAdapter(){
public void mouseDragged(MouseEvent arg0) {
btn.setLocation(btn.getX() + arg0.getX(), btn.getY() + arg0.getY());
pdc.repaint();
}
});
pdc.add(btn);
final JButton btn2 = new JButton("Obj B");
btn2.addMouseMotionListener(new MouseMotionAdapter(){
public void mouseDragged(MouseEvent arg0) {
btn2.setLocation(btn2.getX() + arg0.getX(), btn2.getY() + arg0.getY());
pdc.repaint();