-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFieldPanel.java
More file actions
64 lines (57 loc) · 1.81 KB
/
Copy pathFieldPanel.java
File metadata and controls
64 lines (57 loc) · 1.81 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
import javax.swing.*;
import java.awt.*;
public class FieldPanel extends JPanel
{
private JButton [][] array;
public FieldPanel()
{
super();
setPreferredSize(new Dimension(700, 500));
setLayout(new GridLayout(25, 35));
array = new JButton[25][];
for (int i=0; i<array.length; i++)
{
array[i] = new JButton[35];
for (int j=0; j<array[i].length; j++)
{
array[i][j] = new JButton();
array[i][j].setFocusable(false);
array[i][j].setEnabled(false);
add(array[i][j]);
}
}
}
public void display(Field [][] f)
{
for (int i=0; i<f.length; i++)
{
for (int j=0; j<f[i].length; j++)
{
switch (f[i][j].getProperty())
{
case Field.EMPTY:
array[i][j].setBackground(Color.white);
break;
case Field.FOOD:
array[i][j].setBackground(Color.yellow);
break;
case Field.BODY:
array[i][j].setBackground(Color.black);
break;
case Field.FEDBODY:
array[i][j].setBackground(Color.red);
break;
case Field.HEAD:
array[i][j].setBackground(Color.gray);
break;
case Field.TAIL:
array[i][j].setBackground(Color.green);
break;
case Field.EATING:
array[i][j].setBackground(Color.blue);
break;
}
}
}
}
}