Séparation des classes BoardView et BackgroundLayer

This commit is contained in:
2026-02-03 09:17:10 +01:00
parent fdba5f0f2f
commit 6eb63cacaa
2 changed files with 196 additions and 192 deletions

View 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 limage 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);
}
}
}

View File

@@ -10,7 +10,7 @@ import java.awt.*;
* Elle gère :
* - laffichage des tours (PieceLayer)
* - laffichage des coups possibles (HighlightLayer)
* - laffichage du fond graphique
* - laffichage du fond graphique (BackgroundLayer)
* - les clics via InteractionController
*
* Cette classe ne contient aucune logique de règles du jeu.
@@ -156,37 +156,4 @@ public class BoardView extends JLayeredPane {
}
return grid;
}
//Affichage
/**
* Composant affichant limage de fond.
*/
private static 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);
}
}
}
}