-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChoixTableau.java
More file actions
114 lines (86 loc) · 2.48 KB
/
ChoixTableau.java
File metadata and controls
114 lines (86 loc) · 2.48 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
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class ChoixTableau extends JPanel implements MouseMotionListener
{
private JLabel[] square;
private Icon whiteSquare;
private Icon blueSquare;
public ChoixTableau()
{
super();
GridLayout gl = new GridLayout(8,10);
gl.setHgap(3);
gl.setVgap(3);
setLayout(gl);
square = new JLabel[80];
whiteSquare = new ImageIcon("icons/white-square.png");
blueSquare = new ImageIcon("icons/square_blue.png");
addMouseMotionListener(this);
setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
for(int i = 0; i < 80; i++)
{
square[i] = new JLabel(whiteSquare);
square[i].setName(Integer.toString(i));
square[i].addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent arg0)
{
if(arg0.getSource() instanceof JLabel)
{
int positionClick = Integer.parseInt(arg0.getComponent().getName());
new AttributsTableau(null, "Paramètres tableau", true, (positionClick/10 + 1),(positionClick%10 + 1));
System.out.println("Nombre de lignes : " + (positionClick/10 + 1));
System.out.println("Nombre de colonnes : " + (positionClick%10 + 1));
}
}
});
square[i].addMouseMotionListener(this);
add(square[i]);
}
}
@Override
public void mouseDragged(MouseEvent arg0)
{
// TODO Auto-generated method stub
}
@Override
public void mouseMoved(MouseEvent arg0)
{
if(arg0.getSource() instanceof ChoixTableau)
{
if(arg0.getX() < 10 || arg0.getY() < 10 || arg0.getX() > getWidth() - 10 || arg0.getY() > getHeight() - 10)
{
for(int i = 0; i < square.length; i++)
{
square[i].setIcon(whiteSquare);
}
}
}
if(arg0.getSource() instanceof JLabel)
{
int positionMouse = Integer.parseInt(arg0.getComponent().getName());
int positionXMouse = positionMouse%10;
int positionYMouse = positionMouse/10;
int positionXother, positionYother;
for(int i = 0; i < square.length; i++)
{
positionXother = i%10;
positionYother = i/10;
if(positionXother <= positionXMouse && positionYother <= positionYMouse)
{
square[i].setIcon(blueSquare);
}
else
{
square[i].setIcon(whiteSquare);
}
}
}
}
}