Séparation des classes BoardView et BackgroundLayer
This commit is contained in:
37
fr/iut_fbleau/Avalam/BackgroundLayer.java
Normal file
37
fr/iut_fbleau/Avalam/BackgroundLayer.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package fr.iut_fbleau.Avalam;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* La classe <code>BackgroundLayer</code>
|
||||
*
|
||||
* Sous composant de BoardView affichant l’image de fond.
|
||||
*/
|
||||
public class BackgroundLayer extends JComponent {
|
||||
private Image img;
|
||||
|
||||
/**
|
||||
* Construit une couche de fond.
|
||||
*
|
||||
* @param resourcePath chemin de l'image de fond
|
||||
*/
|
||||
public BackgroundLayer(String resourcePath) {
|
||||
img = Toolkit.getDefaultToolkit().getImage(
|
||||
getClass().getClassLoader().getResource(resourcePath)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dessine l'image de fond.
|
||||
*
|
||||
* @param g contexte graphique
|
||||
*/
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (img != null) {
|
||||
g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user