-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP0605.java
More file actions
160 lines (125 loc) · 3.61 KB
/
P0605.java
File metadata and controls
160 lines (125 loc) · 3.61 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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package P0600;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class P0605 extends JFrame {
public static Color[] buttonColors = { Color.green, Color.orange, Color.yellow, Color.red, Color.gray, Color.cyan};
public static Color[] resultColors;
public static JButton btnres1, btnres2, btnres3, btnres4;
JPanel pnlMain;
JPanel pnlRows;
JPanel pnlTop;
JPanel pnlBottom;
JPanel pnlOptions;
Row pnlRow;
Color green;
Color brown;
public static int numberRows;
public static int currentRowIndex;
public static void main(String[] args) {
P0605 fr = new P0605();
fr.setExtendedState(MAXIMIZED_BOTH);
fr.setVisible(true);
}
public P0605() {
super("MasterMind");
green = new Color(0, 176, 80);
brown = new Color(139,69,19);
numberRows = 12;
currentRowIndex = 0;
resultColors = new Color[4];
initGUI();
}
private void initGUI() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(400,800);
btnres1 = new JButton();
btnres2 = new JButton();
btnres3 = new JButton();
btnres4 = new JButton();
pnlMain = new JPanel();
pnlRows = new JPanel();
pnlTop = new JPanel();
pnlBottom = new JPanel();
pnlOptions = new JPanel();
pnlRows.setBackground(brown);
pnlTop.setBackground(green);
pnlBottom.setBackground(green);
pnlOptions.setBackground(brown);
pnlRows.setLayout(new BoxLayout(pnlRows, BoxLayout.Y_AXIS));
pnlMain.setLayout(new BorderLayout());
pnlTop.setPreferredSize(new Dimension(200, 50));
pnlBottom.setPreferredSize(new Dimension(200, 100));
pnlOptions.setPreferredSize(
new Dimension(this.getWidth()*2, this.getHeight())
);
btnres1.setPreferredSize(new Dimension(50, 50));
btnres2.setPreferredSize(new Dimension(50, 50));
btnres3.setPreferredSize(new Dimension(50, 50));
btnres4.setPreferredSize(new Dimension(50, 50));
btnres1.setEnabled(false);
btnres2.setEnabled(false);
btnres3.setEnabled(false);
btnres4.setEnabled(false);
createColorResult();
for(int i = 0; i < 4; i++) {
System.out.println(resultColors[i]);
}
for(int i = 0; i<numberRows; i++) {
if(i == 0) {
pnlRows.add(new Row(false));
}
else {
pnlRows.add(new Row());
}
}
pnlBottom.add(btnres1);
pnlBottom.add(btnres2);
pnlBottom.add(btnres3);
pnlBottom.add(btnres4);
pnlMain.add(BorderLayout.CENTER, pnlRows);
pnlMain.add(BorderLayout.NORTH, pnlTop);
pnlMain.add(BorderLayout.SOUTH, pnlBottom);
getContentPane().add(BorderLayout.CENTER, pnlMain);
// getContentPane().add(BorderLayout.EAST, pnlOptions);
}
/**
* Créé une combinaison de couleur aléatoirement
*/
private void createColorResult() {
Random rand = new Random();
List<Color> colors = SetList(buttonColors);
for(int i = 0; i < 4; i++) {
int ran = rand.nextInt(colors.size());
resultColors[i] = colors.get(ran);
colors.remove(ran);
}
}
public Row[] getRows() {
List<Row> rows = new ArrayList<>();
for(int i = 0; i < pnlRows.getComponentCount(); i++) {
rows.add((Row)pnlRows.getComponent(i));
}
Row[] newRows = new Row[rows.size()];
rows.toArray(newRows);
return newRows;
}
private List<Color> SetList(Color[] guessColors) {
// TODO Auto-generated method stub
List<Color> colors = new ArrayList<Color>();
for(Color c : guessColors) {
colors.add(c);
}
return colors;
}
}