1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| public void paintComponent(Graphics g) {
int x, y, laff, haff, ltxt, htxt;
Color c;
String texte;
if (laFile.estVide()) {
c = Color.green;
texte = "Pas de valeur !";
} else {
texte = "Tete : " + laFile.valeurEnTete();
if (laFile.estSaturee()) {
c = Color.red;
} else {
c = Color.orange;
}
}
laff = getWidth();
haff = getHeight();
Font maPolice = new Font("Arial", Font.BOLD, haff / 6);
g.setFont(maPolice);
FontMetrics fm = g.getFontMetrics();
ltxt = fm.stringWidth(texte);
htxt = fm.getAscent();
x = (laff - ltxt) / 2;
y = (haff - htxt) / 2;
g.setColor(c);
g.fillRect(0, 0, laff, haff);
g.setColor(Color.black);
g.drawString(texte, x, y);
texte = laFile.toString();
ltxt = fm.stringWidth(texte);
x = (laff - ltxt) / 2;
y = (haff + htxt) / 2;
g.drawString(texte, x, y);
} |
Partager