28 lines
835 B
Java
28 lines
835 B
Java
|
import javax.swing.*;
|
||
|
import java.awt.*;
|
||
|
|
||
|
public class AfficheImage extends JComponent {
|
||
|
private Image fond;
|
||
|
|
||
|
public AfficheImage(String cheminImage) {
|
||
|
super();
|
||
|
this.fond = Toolkit.getDefaultToolkit().getImage(cheminImage);
|
||
|
}
|
||
|
@Override
|
||
|
public Dimension getPreferredSize() {
|
||
|
return new Dimension(288, 215);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected void paintComponent(Graphics pinceau) {
|
||
|
Graphics secondPinceau = pinceau.create();
|
||
|
if (this.isOpaque()) {
|
||
|
secondPinceau.setColor(this.getBackground());
|
||
|
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||
|
}
|
||
|
int x = (this.getWidth() - fond.getWidth(this)) / 2;
|
||
|
int y = (this.getHeight() - fond.getHeight(this)) / 2;
|
||
|
secondPinceau.drawImage(this.fond, x, y, this);
|
||
|
}
|
||
|
}
|