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
| class panneau extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
pan.removeAll();
Graphics2D graphics2D = (Graphics2D) g;
graphics2D.setStroke(new BasicStroke( 5.0f ));
// Dessin des contours
g.drawLine(0,0,540,0);
g.drawLine(0,540,540,540);
g.drawLine(0,0,0,540);
g.drawLine(540,0,540,540);
// Dessin des séparations intérieurs
g.drawLine(0,180,540,180);
g.drawLine(0,360,540,360);
g.drawLine(180,0,180,540);
g.drawLine(360,0,360,540);
graphics2D.setStroke(new BasicStroke(1.0f));
// Dessin des grilles
for (int i=0;i<9;i++) {
for (int j=0;j<9;j++) {
if (tab[i+j*9] == 0) { // Case vide
g.setColor(Color.black);
g.drawRect(i*60,j*60,60,60);
tabsaisie[i+j*9] = new JTextField(1);
tabsaisie[i+j*9].setBounds(i*60+15,j*60+15,30,30);
tabsaisie[i+j*9].setBorder(null);
pan.add(tabsaisie[i+j*9]);
tabsaisie[i+j*9].addActionListener(this) ;
tabsaisie[i+j*9].addFocusListener(this) ;
}
else {
g.setColor(Color.black);
g.drawRect(i*60,j*60,60,60);
resultat = new JTextField(1);
resultat.setBounds(i*60+15,j*60+15,30,30);
resultat.setBorder(null);
resultat.setBackground(Color.white);
resultat.setText(Integer.toString(tab[i+j*9]));
resultat.setEditable(false);
pan.add(resultat);
}
}
}
}
}
public void actionPerformed (ActionEvent e) { }
public void focusGained (FocusEvent e) {}
public void focusLost (FocusEvent e) {
// Traitement de la valeur
} |
Partager