-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResourcePanel.java
More file actions
64 lines (53 loc) · 2.29 KB
/
Copy pathResourcePanel.java
File metadata and controls
64 lines (53 loc) · 2.29 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
package Grafica.JavaClashOfClans;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public class ResourcePanel extends JPanel {
private Color resourceColor;
private int widthImg, heightImg, paddingInternal, width, height, paddingY, resourceValue, resourceMaxValue;
private JLabel valueLabel;
public ResourcePanel(MainWindow mainWindow, BufferedImage resourceImg, Color resourceColor, int resourceValue, int resourceMaxValue, int width, int height, int paddingX, int paddingY) {
int rightX = MainWindow.calcRightX(mainWindow, paddingX);
setLayout(null);
setOpaque(false); //? rendere il pannello con il background trasparente
setBorder(BorderFactory.createLineBorder(Color.black));
setBounds(rightX-width, paddingY, width, height);
this.resourceMaxValue = resourceMaxValue;
this.resourceValue = resourceValue;
this.resourceColor = resourceColor;
this.paddingY = paddingY;
this.paddingInternal = 10;
this.width = width;
this.height = height;
this.widthImg = resourceImg.getWidth();
this.heightImg = resourceImg.getHeight();
JPanel resourceImage = new JPanel(){
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(resourceImg, 0, 0, null);
}
};
resourceImage.setBounds(width-(widthImg+paddingInternal), (height-heightImg)/2+1, widthImg, height);
resourceImage.setOpaque(false);
this.valueLabel = new JLabel(resourceValue+" ");
valueLabel.setHorizontalAlignment(SwingConstants.RIGHT);
valueLabel.setForeground(Color.white);
valueLabel.setBounds(0, 0, width-(widthImg+paddingInternal), height);
add(resourceImage);
add(valueLabel);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(resourceColor);
int widthPercInPixel = resourceValue*width/resourceMaxValue;
g.fillRect(width-widthPercInPixel,0,widthPercInPixel,height);
}
public void recreate(int max, int value) {
this.resourceMaxValue = max;
this.resourceValue = value;
valueLabel.setText(value+" ");
repaint();
}
}