-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.java
More file actions
64 lines (50 loc) · 1.87 KB
/
Copy pathMainWindow.java
File metadata and controls
64 lines (50 loc) · 1.87 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.*;
public class MainWindow extends JFrame {
//! EDIT THIS PATH IF IMAGES DOESN'T APPEAR
public static String assetsPath = "Grafica/JavaClashOfClans/assets";
private CardLayout cardLayout;
GamePanel gamePanel;
ShopPanel shopPanel;
public MainWindow(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(400,50, 1185, 950);
setResizable(false);
//? inizializzazione del layout
cardLayout = new CardLayout();
getContentPane().setLayout(cardLayout);
//? aggiunta dei pannelli al pannello con CardLayout
gamePanel = new GamePanel(15, 44, 50, this);
shopPanel = new ShopPanel(this);
getContentPane().add(gamePanel, "Game");
getContentPane().add(shopPanel, "Shop");
setVisible(true);
}
void switchGameState(String cardName) {
cardLayout.show(getContentPane(), cardName);
}
public GamePanel getGamePanel() {
return gamePanel;
}
static int calcRightX(MainWindow mainWindow, int padding) {
int border;
if (mainWindow.getInsets().left == 0) {
border = 8;
} else {
border = mainWindow.getInsets().left;
}
//? utilizzo il metodo getBounds perché come scritto nelle docs garantisce prestazioni migliori nella memoria
return mainWindow.getBounds().width - border - padding;
}
static int calcBottomY(MainWindow mainWindow, int padding) {
int border;
if (mainWindow.getInsets().left == 0) {
border = 31;
} else {
border = mainWindow.getInsets().left;
}
//? utilizzo il metodo getBounds perché come scritto nelle docs garantisce prestazioni migliori nella memoria
return mainWindow.getBounds().height - border - padding;
}
}