forked from EduGiehl/Banco-Imobiliario
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTabuleiroPrint.java
45 lines (35 loc) · 1.33 KB
/
TabuleiroPrint.java
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
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public class TabuleiroPrint {
private BufferedImage tabuleiro;
public TabuleiroPrint(BufferedImage tabuleiro) {
this.tabuleiro = tabuleiro;
}
public int getX(){
return this.tabuleiro.getWidth();
}
public int getY(){
return this.tabuleiro.getHeight();
}
public void desenhar(Graphics g, int panelWidth, int panelHeight) {
// Redimensiona a imagem do tabuleiro para se ajustar ao tamanho do painel
if (tabuleiro != null) {
int tabWidth = panelWidth;
int tabHeight = panelHeight;
double tabAspect = (double) tabuleiro.getWidth() / tabuleiro.getHeight();
double panelAspect = (double) panelWidth / panelHeight;
int newTabWidth, newTabHeight;
if (panelAspect > tabAspect) {
newTabHeight = panelHeight;
newTabWidth = (int) (newTabHeight * tabAspect);
} else {
newTabWidth = panelWidth;
newTabHeight = (int) (newTabWidth / tabAspect);
}
int tabX = (panelWidth - newTabWidth) / 2;
int tabY = (panelHeight - newTabHeight) / 2;
g.drawImage(tabuleiro, tabX, tabY, newTabWidth, newTabHeight, null);
}
}
}