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