-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShopItemPanel.java
More file actions
83 lines (57 loc) · 2.44 KB
/
Copy pathShopItemPanel.java
File metadata and controls
83 lines (57 loc) · 2.44 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package Grafica.JavaClashOfClans;
import Grafica.JavaClashOfClans.builds.Build;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
public class ShopItemPanel extends JPanel {
private int width, height;
private BufferedImage gold, elixir;
ShopItemPanel(Build build, int width, MainWindow mainWindow) {
super(null);
try {
File goldImg = new File(MainWindow.assetsPath +"/images/gold.png");
gold = ImageIO.read(goldImg);
File elixirImg = new File(MainWindow.assetsPath +"/images/elixir.png");
elixir = ImageIO.read(elixirImg);
} catch (Exception ignored) {}
JLabel nameLabel = new JLabel(build.getName(), SwingConstants.CENTER);
nameLabel.setBounds(0,0,width,50);
add(nameLabel);
JPanel costPanel = new JPanel();
costPanel.setBounds(20,50,width-(20*2), 50);
costPanel.setBorder(BorderFactory.createLineBorder(new Color(66,49,137)));
JLabel baseCost = new JLabel(build.getBaseCost()+"");
baseCost.setFont(new Font("", Font.BOLD, 20));
costPanel.add(baseCost);
JPanel typeCostImagePanel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (build.getTypeCost().equals("gold")) {
g.drawImage(gold, 0, 0, 25, 25, this);
} else if (build.getTypeCost().equals("elixir")) {
g.drawImage(elixir, 0, 0, 25, 25, this);
}
}
};
//? imposto le dimensioni del pannello che contiene l'immagine perché se no non si modella in base alla grandezza dell'immagine
typeCostImagePanel.setPreferredSize(new Dimension(25, 25));
costPanel.add(typeCostImagePanel);
add(costPanel);
JPanel buildImagePanel = new JPanel(){
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(build.getBuildImg(), 0, 0, 150, 150, this);
}
};
buildImagePanel.setBounds((width-150)/2,125,150,150);
add(buildImagePanel);
JButton btn = new ShopItemButton(mainWindow, build);
btn.setBounds(20,300,width-(20*2),50);
add(btn);
setBorder(BorderFactory.createLineBorder(Color.black));
}
}