APL/APL2.1/TP13/Image/ImagePanel.java
2022-05-16 17:29:36 +02:00

23 lines
571 B
Java

import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Image;
public class ImagePanel extends JPanel {
private Image img;
public ImagePanel(Image img) {
super();
this.img = img;
}
@Override
protected void paintComponent(Graphics g) {
Graphics newG = g.create();
if (this.isOpaque()) {
newG.setColor(this.getBackground());
newG.fillRect(0, 0, this.getWidth(), this.getHeight());
}
newG.drawImage(img, 0, 0, img.getWidth(this), img.getHeight(this), this);
}
}