// 我的代码调用要放置在 JPanel 上的目录中的 n 个图像
public void imageAdder(int n, String name){
BufferedImage myPic = null;
for (int i = 0; i <= n; i++){
try {
myPic = ImageIO.read(new File("Images/" + name + i + ".jpg"));
} catch (Exception e){
System.out.println("no file man cmon");
}
JLabel picLabel = new JLabel(new ImageIcon(myPic));
// picLabel.setBounds(mouseX, mouseY, 100, 50);
// picLabel.addMouseMotionListener(this);
// picLabel.addMouseListener(this);
canvas.add(picLabel);
}}
Run Code Online (Sandbox Code Playgroud)
我阅读了类 DragSource 以及如何有一种方法可以拖动图像类型的东西,但我不确定这是否适用于我的代码。如果我想用鼠标自由拖动图像怎么办?