/**
*
* @author Administrador
*/
public class jTriqui extends javax.swing.JFrame {
String letra="X";
Integer x=0,y=0;
JButton[][] botones=new JButton[3][3];
/** Creates new form jTriqui */
public jTriqui() {
initComponents();
for (int i=0; i<3;i++){
for (int j=0; j<3;j++){
botones[i][j]=new JButton("");
botones[i][j].setBounds((i*200)+10, (j*200)+10,200,200);
this.add(botones[i][j]);
botones[i][j].setVisible(true);
botones[i][j].addActionListener(escuchador);
}
}
}
ActionListener escuchador=new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
for (int i=0; i<3;i++){
for (int j=0; j<3;j++){
if (botones [i][j].equals(e.getSource())){
x=i;
y=j;
if (botones [i][j].getText().equals("")){
if (letra.equals("X")){ letra="o";}
else {letra="X";}
botones[i][j].setText(letra);
}
}
}
}
{
if ((botones[x][y].getText().equals(botones[x+1][y+1].getText()))
&&(botones[x][y].getText().equals(botones[x+1][y+1].getText()))){
JOptionPane.showMessageDialog(null,"TRIQUI");} }
}
};
No hay comentarios:
Publicar un comentario