图片以label为载体,给按钮注册actionlistener,在事件中重设label的位置就好了
就像楼上说的,把图片放到label中,然后设置label的位置
private int x = jLabel1.getX();
private int y = jLabel1.getY();
jmove.setLocation(x+10, y);
private int x=0,y=0;
private final Random random = new Random();
public void paintComponent(Graphics g){
g.drawImage(x,y, image, null);
}
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
x = x + random.nextInt(10);
y = y + random.nextInt(10);
update();
}
}