This repository has been archived by the owner on Mar 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVue.java
135 lines (114 loc) · 3.34 KB
/
Vue.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
* Created by Dastan21
*/
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.*;
public class Vue extends JFrame {
protected Model model;
/* Panels */
protected JPanel pTout;
protected JPanel pPlateau;
protected JPanel pGrille;
/* Options menu */
protected JMenuBar barMenuOptions;
protected JMenu menuOptions;
protected JMenuItem menuOptionsNP;
protected JMenuItem menuOptionsAP;
// Boutons
protected KButton[][] tabBoutons;
protected ActionListener[][] tabListeners;
public Vue(Model model){
this.model = model;
initMenu();
initGrid();
creerMenu();
creerVue();
setTitle("Kamisado");
setVisible(true);
setResizable(false);
pack();
setLocationRelativeTo(null);
setIconImage(Toolkit.getDefaultToolkit().getImage("Images/kamisado_logo.png"));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void initGrid(){
// Instanciation du tableau de boutons
tabBoutons = new KButton[8][8];
for (int i = 0; i < 8; i++){
for (int j = 0; j < 8; j++){
tabBoutons[i][j] = new KButton();
tabBoutons[i][j].setPreferredSize(new Dimension(64, 64));
}
}
tabListeners = new ActionListener[8][8];
}
private void initMenu(){
// Instanciations des éléments du menu
barMenuOptions = new JMenuBar();
menuOptions = new JMenu("Options");
menuOptionsNP = new JMenuItem("Nouvelle partie");
menuOptionsAP = new JMenuItem("À propos");
}
private void creerVue(){
/* Instanciations */
pTout = new JPanel();
pPlateau = new JPanel();
pGrille = new JPanel();
/* Layouts */
pPlateau.setLayout(new BoxLayout(pPlateau, BoxLayout.Y_AXIS));
pPlateau.setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.black));
pGrille.setLayout(new GridLayout(8,8));
/* Boutons sans bord */
for (KButton[] listBtn : tabBoutons){
for (KButton btn : listBtn){
btn.setBorder(BorderFactory.createEmptyBorder());
}
}
/* Assemblages */
pTout.add(pPlateau);
pPlateau.add(pGrille);
for (KButton[] listBtn : tabBoutons){
for (KButton btn : listBtn){
pGrille.add(btn);
}
}
setContentPane(pTout);
}
private void creerMenu(){
menuOptions.add(menuOptionsNP);
menuOptions.addSeparator();
menuOptions.add(menuOptionsAP);
barMenuOptions.add(menuOptions);
setJMenuBar(barMenuOptions);
}
public void setButtonControler(ActionListener listener){
// for (KButton[] listBtn : tabBoutons){
// for (KButton btn : listBtn){
// btn.addActionListener(listener);
//
// }
// }
for (int i = 0; i < 8; i++){
for (int j = 0; j < 8; j++){
tabBoutons[i][j].addActionListener(listener);
tabListeners[i][j] = listener;
}
}
}
public void setMenuControler(ActionListener listener){
menuOptionsNP.addActionListener(listener);
menuOptionsAP.addActionListener(listener);
}
public void creerDialog(String msg){
JOptionPane dialog = new JOptionPane();
dialog.showMessageDialog(this, msg);
JDialog fenDialog = dialog.createDialog(this, msg);
}
/* Geters des éléments en interactions */
public JMenuItem getMenuOptionsNP() { return menuOptionsNP; }
public JMenuItem getMenuOptionsAP() { return menuOptionsAP; }
public KButton getBouton(int i, int j) { return tabBoutons[i][j]; }
}