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
| public class PanGeneral extends JPanel {
JPanel panHaut = new panh.PanH0();
JPanel panCentral = new panc.PanC0();
JPanel panBas = new panb.PanB0();
private Image fond, zoom;
private double largeurFrame = (LaFrame.largeurEcran * 80d) / 100d;
private double hauteurFrame = (LaFrame.hauteurEcran * 80d) / 100d;
private int lf = (int) largeurFrame;
private int hf = (int) hauteurFrame;
public PanGeneral() {
this.setOpaque(false);
this.setLayout(new BorderLayout());
try {
fond = ImageIO.read(this.getClass().getResource("/base/fondfirstgame2.png"));
} catch (IOException e) {e.printStackTrace(); }
zoom = scaleImage(fond, lf, hf);
this.add(panHaut, BorderLayout.NORTH);
this.add(panCentral, BorderLayout.CENTER);
this.add(panBas, BorderLayout.SOUTH);
}
public void paintComponent (Graphics g) {
g.drawImage(zoom, 0, 0, lf, hf, this);
}
public static Image scaleImage(Image source, int width, int height) {
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D) img.getGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(source, 0, 0, width, height, null);
g.dispose();
return img;
}
} |
Partager