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
| private Font font = new Font("Dialog", Font.ITALIC, 24);
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
double scalex = (double)this.getWidth() / (double) image.getWidth();
double scaley = (double)this.getHeight() / (double) image.getHeight();
g2d.scale(scalex, scaley);
fillBackground(g2d, image, anchorY, getWidth() / scalex, getHeight() / scaley);
g2d.scale(1 / scalex, 1 / scaley);
g2d.setColor(Color.LIGHT_GRAY);
//g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2d.setFont(font);
g2d.drawString("Vies : " + vie + "%", 10, 30);
g2d.drawString("Scores : " + score, 1100, 30);
g2d.drawString("Missiles : 000 ", 1100, 60);
// Afficher le vecteur
for(int i=0;i<elements.size();i++)
{
elements.get(i).paintComponent(g);
}
}
protected void fillBackground(Graphics2D g, BufferedImage image, int anchorY, double width, double height) {
Shape oldClip = g.getClip();
g.setClip(new Rectangle(0, 0, (int) width, (int) height));
int imageWidth = image.getWidth();
int imageHeight = image.getHeight();
for (int j = -imageHeight + anchorY; j < height; j += imageHeight) {
for (int i = 0; i < width; i += imageWidth) {
g.drawImage(image, i, j, null);
}
}
g.setClip(oldClip);
} |
Partager