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
| class MasterMind {
class Jeton extends JComponent {
public Jeton() {
super();
addMouseListener(new MouseListener() {
/*Invoked when the mouse button has been clicked (pressed and released) on a component. */
void mouseClicked(MouseEvent e) {}
/*Invoked when the mouse enters a component. */
void mouseEntered(MouseEvent e) {}
/* Invoked when the mouse exits a component. */
void mouseExited(MouseEvent e) {}
/*Invoked when a mouse button has been pressed on a component.*/
void mousePressed(MouseEvent e) {}
/* Invoked when a mouse button has been released on a component.*/
void mouseReleased(MouseEvent e) {}
});
}
public void paintComponent(Graphics g) {
// dessine le bouton sur le composant graphique Swing
}
}
public static void main(String[] args) {
JFrame masterm = new JFrame("MasterMind");
Container plateau = masterm.getContentPane();
plateau.setLayout(new GridBagLayout());
for(int i = 0; i < 60; i++) {
// chaque jeton est inseré
Jeton jeton; GridBagConstraints c = new GridBagConstraints();
plateau.add(jeton = new Jeton());
// nouvelle ligne
c.gridwidth = GridBagConstraints.REMAINDER;
if((i % 5) == 4)
((GridBagLayout)plateau.getLayout()).setConstraints((Component)jeton, c);
}
masterm.setVisible(true); masterm.pack(); masterm.setLocationRelativeTo(null);
}
} |
Partager