-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFond.java
More file actions
66 lines (56 loc) · 1.54 KB
/
Fond.java
File metadata and controls
66 lines (56 loc) · 1.54 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* La classe <code>Fond</code> est destine a afficher le fond
* et le score si donné au constructeur
* @version 0.1
* @author Morgan Jully et Killian Mocret
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import javax.imageio.*;
import java.lang.*;
public class Fond extends JComponent{
/**
* Image a mettre en fond
*/
private Image fond;
/**
* Le score a affiche
*/
private int score = -1;
/**
* Constructeur destine a recuperer le chemin
* vers l'image a afficher en fond
* @param s : la chaine de caractere
*/
public Fond(String s) {
super();
this.fond = getToolkit().getImage(this.getClass().getResource(s));
}
/**
* Constrcuteur destine a afficher l image et le score
*/
public Fond(String s, int score) {
super();
this.fond = getToolkit().getImage(this.getClass().getResource(s));
this.score = score;
}
public void paintComponent(Graphics g) {
if (this.isOpaque()) {
g.setColor(this.getBackground());
g.fillRect(0, 0, this.getWidth(), this.getHeight());
}
g.drawImage(this.fond, 0, 0, this);
if(this.score > 0) {
Font f = null;
try {
f = Font.createFont(0, getClass().getResourceAsStream("/font/comic.ttf")).deriveFont(Font.BOLD,25F);
} catch(Exception e) {
System.out.println("Erreur d'ouverture");
}
g.setFont(f);
g.drawString("Score : "+this.score, 100, 250);
}
}
}