Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionimport java.awt.GridLayout; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JPanel; public class TicTacToe extends JFrame { private static final long serialVersionUID = 4662858280923146647L; public TicTacToe(){ setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(600, 600); setLocationRelativeTo(null); setLayout(new GridLayout(3, 3)); for(int i=0; i<9; i++){ JPanel caseGrille = new JPanel(); caseGrille.setBorder(BorderFactory.createEtchedBorder()); add(caseGrille); } setVisible(true); } public static void main(String[] args){ new TicTacToe(); } }
import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class TicTacToe extends JFrame { private static final long serialVersionUID = 4662858280923146647L; private static boolean croix=true; public TicTacToe(){ setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(600, 600); setLocationRelativeTo(null); setLayout(new GridLayout(3, 3)); for(int i=0; i<9; i++){ final JButton caseGrille = new JButton(); caseGrille.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if(croix){ caseGrille.setText("X"); } else { caseGrille.setText("O"); } croix=!croix; } }); add(caseGrille); } setVisible(true); } public static void main(String[] args){ new TicTacToe(); } }