java中怎样实现图片拖动
java中怎样实现图片的拖动,我的代码如下,我的问题是怎样让图片整个显示,我的代码的问题是图片拖动后只能显示图片的一部分,求高手指点:import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
public class DragTest_02 extends JFrame {
Point pStart = new Point();
Point pEnd = new Point();
Icon img = new ImageIcon(this.getClass().getResource("/img/jinan.jpg"));
JLabel JL = new JLabel(img);
JPanel p = new JPanel();
public DragTest_02() {
setBounds(300, 200, 500, 500);
setLayout(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(null);
add(JL);
add(JL);
JL.setBounds(10, 10, 80, 100);
JL.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
pStart.x = JL.getX();
pStart.y = JL.getY();
}
});
JL.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
pEnd.x = e.getX();
pEnd.y = e.getY();
JL.setLocation(pEnd);
}
});
JL.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
pEnd.x = e.getX();
pEnd.y = e.getY();
JL.setLocation(pEnd);
}
});
setVisible(true);
}
public static void main(String[] args) {
new DragTest_02();
}
}