1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| public class MyImagePanel extends JPanel {
private int x;
private int y;
private BufferedImage img;
/**
* @param x
* @param y
* @param img
*/
public MyImagePanel(int x, int y, BufferedImage img) {
super();
// TODO Auto-generated constructor stub
this.x = x;
this.y = y;
this.img = img;
}
public BufferedImage getImg() {
return img;
}
public void setImg(BufferedImage img) {
this.img = img;
SwingUtilities.invokeLater(repaint());
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
SwingUtilities.invokeLater(repaint());
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
SwingUtilities.invokeLater(repaint());
}
@Override
protected void paintComponent(Graphics arg0) {
// TODO Auto-generated method stub
arg0.drawImage(img,x,y,null);
super.paintComponent(arg0);
}
} |
Partager