- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResourcePanel.java
More file actions
Latest commit
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
packageGrafica.JavaClashOfClans;
importjavax.swing.*;
importjava.awt.*;
importjava.awt.image.BufferedImage;
publicclassResourcePanelextendsJPanel {
privateColorresourceColor;
privateintwidthImg, heightImg, paddingInternal, width, height, paddingY, resourceValue, resourceMaxValue;
privateJLabelvalueLabel;
publicResourcePanel(MainWindowmainWindow, BufferedImageresourceImg, ColorresourceColor, intresourceValue, intresourceMaxValue, intwidth, intheight, intpaddingX, intpaddingY) {
intrightX = 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();
JPanelresourceImage = newJPanel(){
@Override
protectedvoidpaintComponent(Graphicsg) {
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 = newJLabel(resourceValue+" ");
valueLabel.setHorizontalAlignment(SwingConstants.RIGHT);
valueLabel.setForeground(Color.white);
valueLabel.setBounds(0, 0, width-(widthImg+paddingInternal), height);
add(resourceImage);
add(valueLabel);
}
@Override
protectedvoidpaintComponent(Graphicsg) {
super.paintComponent(g);
g.setColor(resourceColor);
intwidthPercInPixel = resourceValue*width/resourceMaxValue;
g.fillRect(width-widthPercInPixel,0,widthPercInPixel,height);
}
publicvoidrecreate(intmax, intvalue) {
this.resourceMaxValue = max;
this.resourceValue = value;
valueLabel.setText(value+" ");
repaint();
}
}