Site Wide Message: (current site time 9/2/2010 11:17:44 AM EDT)
  • We want your input! One of our sponsors wants to know your opinion about development related issues. Click here to tell us what you think.
  • Are you an emerging/young developer (aged 18-30)? If so, would you like the chance to affect future developer tools and products?
    If so, then click here to give your feedback.
 

xo

Print
Email
VB icon
Submitted on: 1/28/2010 8:41:59 AM
By: ahmed wagih 
Level: Intermediate
User Rating: Unrated
Compatibility:Java (JDK 1.1), Java (JDK 1.2), Java (JDK 1.3), Java (JDK 1.4), Java (JDK 1.5)

Users have accessed this code  1841 times.
 
 
     playing x o game
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: xo
// Description:playing x o game
// By: ahmed wagih
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=6568&lngWId=2//for details.//**************************************

import java.awt.Color;
import javax.swing.JOptionPane;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
 * XO.java
 *
 * Created on Jan 24, 2010, 9:59:30 PM
 */
/**
 *
 * @author WIGO
 */
public class XO extends javax.swing.JFrame {
int x=1; //determines el Turns player 1 aw 2
int z=1;
void drawzz()
{if(z==9){
 button1.setLabel("");
 button2.setLabel("");
 button3.setLabel("");
 button4.setLabel("");
 button5.setLabel("");
 button6.setLabel("");
 button7.setLabel("");
 button8.setLabel("");
 button9.setLabel("");
 JOptionPane.showMessageDialog(null, "draw");
}}
void checko () // bet7aded elO hateksab wla la2
{
 if(((button1.getLabel().equals("O")))&&((button2.getLabel().equals("O")))&&((button3.getLabel().equals("O"))))
 { 
 button1.setBackground(Color.red);
 button2.setBackground(Color.red);
 button3.setBackground(Color.red);
 JOptionPane.showMessageDialog(null, "2ndPlayer WIN");
 button1.setLabel("");
 button2.setLabel("");
 button3.setLabel("");
 button4.setLabel("");
 button5.setLabel("");
 button6.setLabel("");
 button7.setLabel("");
 button8.setLabel("");
 button9.setLabel("");
button1.setBackground(Color.black);
 button2.setBackground(Color.black);
 button3.setBackground(Color.black);
 
 }
 if(((button4.getLabel().equals("O")))&&((button5.getLabel().equals("O")))&&((button6.getLabel().equals("O"))))
 {
 button4.setBackground(Color.red);
 button5.setBackground(Color.red);
 button6.setBackground(Color.red);
 JOptionPane.showMessageDialog(null, "2ndPlayer WIN"); button1.setLabel(""); button2.setLabel(""); button3.setLabel(""); button4.setLabel(""); button5.setLabel(""); button6.setLabel(""); button7.setLabel(""); button8.setLabel(""); button9.setLabel("");textField2.setText((textField2.getText())+"l");
 button1.setLabel("");
 button2.setLabel("");
 button3.setLabel("");
 button4.setLabel("");
 button5.setLabel("");
 button6.setLabel("");
 button7.setLabel("");
 button8.setLabel("");
 button9.setLabel("");textField2.setText((textField2.getText())+"l");
 button4.setBackground(Color.black);
 button5.setBackground(Color.black);
 button6.setBackground(Color.black);
 }
 if(((button7.getLabel().equals("O")))&&((button8.getLabel().equals("O")))&&((button9.getLabel().equals("O"))))
 {
 button7.setBackground(Color.red);
 button8.setBackground(Color.red);
 button9.setBackground(Color.red);
 JOptionPane.showMessageDialog(null, "2ndPlayer WIN"); button1.setLabel(""); button2.setLabel(""); button3.setLabel(""); button4.setLabel(""); button5.setLabel(""); button6.setLabel(""); button7.setLabel(""); button8.setLabel(""); button9.setLabel("");textField2.setText((textField2.getText())+"l");
 button7.setBackground(Color.black);
 button8.setBackground(Color.black);
 button9.setBackground(Color.black);
 }
 if(((button1.getLabel().equals("O")))&&((button4.getLabel().equals("O")))&&((button7.getLabel().equals("O"))))
 {
 button1.setBackground(Color.red);
 button4.setBackground(Color.red);
 button7.setBackground(Color.red);
 JOptionPane.showMessageDialog(null, "2ndPlayer WIN"); button1.setLabel(""); button2.setLabel(""); button3.setLabel(""); button4.setLabel(""); button5.setLabel(""); button6.setLabel(""); button7.setLabel(""); button8.setLabel(""); button9.setLabel("");textField2.setText((textField2.getText())+"l");
 button1.setBackground(Color.black);
 button4.setBackground(Color.black);
 button7.setBackground(Color.black);}
 if(((button2.getLabel().equals("O")))&&((button5.getLabel().equals("O")))&&((button8.getLabel().equals("O"))))
 {
 button2.setBackground(Color.red);
 button5.setBackground(Color.red);
 button8.setBackground(Color.red);
 JOptionPane.showMessageDialog(null, "2ndPlayer WIN"); button1.setLabel(""); button2.setLabel(""); button3.setLabel(""); button4.setLabel(""); button5.setLabel(""); button6.setLabel(""); button7.setLabel(""); button8.setLabel(""); button9.setLabel("");textField2.setText((textField2.getText())+"l");
button2.setBackground(Color.black);
 button5.setBackground(Color.black);
 button8.setBackground(Color.black);}
 if(((button3.getLabel().equals("O")))&&((button9.getLabel().equals("O")))&&((button6.getLabel().equals("O"))))
 {
 button9.setBackground(Color.red);
 button6.setBackground(Color.red);
 button3.setBackground(Color.red);
 JOptionPane.showMessageDialog(null, "2ndPlayer WIN"); button1.setLabel(""); button2.setLabel(""); button3.setLabel(""); button4.setLabel(""); button5.setLabel(""); button6.setLabel(""); button7.setLabel(""); button8.setLabel(""); button9.setLabel("");textField2.setText((textField2.getText())+"l");
button9.setBackground(Color.black);
 button6.setBackground(Color.black);
 button3.setBackground(Color.black); }
 if(((button1.getLabel().equals("O")))&&((button5.getLabel().equals("O")))&&((button9.getLabel().equals("O"))))
 {
 button1.setBackground(Color.red);
 button5.setBackground(Color.red);
 button9.setBackground(Color.red);
 JOptionPane.showMessageDialog(null, "2ndPlayer WIN"); button1.setLabel(""); button2.setLabel(""); button3.setLabel(""); button4.setLabel(""); button5.setLabel(""); button6.setLabel(""); button7.setLabel(""); button8.setLabel(""); button9.setLabel("");textField2.setText((textField2.getText())+"l");
 button1.setBackground(Color.black);
 button5.setBackground(Color.black);
 button9.setBackground(Color.black);}
 if(((button5.getLabel().equals("O")))&&((button7.getLabel().equals("O")))&&((button3.getLabel().equals("O"))))
 {
 button7.setBackground(Color.red);
 button5.setBackground(Color.red);
 button3.setBackground(Color.red);
 JOptionPane.showMessageDialog(null, "2ndPlayer WIN"); button1.setLabel(""); button2.setLabel(""); button3.setLabel(""); button4.setLabel(""); button5.setLabel(""); button6.setLabel(""); button7.setLabel(""); button8.setLabel(""); button9.setLabel("");textField2.setText((textField2.getText())+"l");
 button7.setBackground(Color.black);
 button5.setBackground(Color.black);
 button3.setBackground(Color.black);}
 
}
void check ()
{
 if(((button1.getLabel().equals("X")))&&((button2.getLabel().equals("X")))&&((button3.getLabel().equals("X"))))
 { 
 button1.setBackground(Color.red);
 button2.setBackground(Color.red);
 button3.setBackground(Color.red);
 JOptionPane.showMessageDialog(null, "1stPlayer WIN"); button1.setLabel(""); button2.setLabel(""); button3.setLabel(""); button4.setLabel(""); button5.setLabel(""); button6.setLabel(""); button7.setLabel(""); button8.setLabel(""); button9.setLabel("");textField1.setText((textField1.getText())+"l");
 button1.setBackground(Color.black);
 button2.setBackground(Color.black);
 button3.setBackground(Color.black);}
 if(((button4.getLabel().equals("X")))&&((button5.getLabel().equals("X")))&&((button6.getLabel().equals("X"))))
 {
 button4.setBackground(Color.red);
 button5.setBackground(Color.red);
 button6.setBackground(Color.red);
 JOptionPane.showMessageDialog(null, "1stPlayer WIN"); button1.setLabel(""); button2.setLabel(""); button3.setLabel(""); button4.setLabel(""); button5.setLabel(""); button6.setLabel(""); button7.setLabel(""); button8.setLabel(""); button9.setLabel("");textField1.setText((textField1.getText())+"l");
 button4.setBackground(Color.black);
 button5.setBackground(Color.black);
 button6.setBackground(Color.black);}
 if(((button7.getLabel().equals("X")))&&((button8.getLabel().equals("X")))&&((button9.getLabel().equals("X"))))
 {
 button7.setBackground(Color.red);
 button8.setBackground(Color.red);
 button9.setBackground(Color.red);
 JOptionPane.showMessageDialog(null, "1stPlayer WIN"); button1.setLabel(""); button2.setLabel(""); button3.setLabel(""); button4.setLabel(""); button5.setLabel(""); button6.setLabel(""); button7.setLabel(""); button8.setLabel(""); button9.setLabel("");textField1.setText((textField1.getText())+"l");
 button7.setBackground(Color.black);
 button8.setBackground(Color.black);
 button9.setBackground(Color.black);}
 if(((button1.getLabel().equals("X")))&&((button4.getLabel().equals("X")))&&((button7.getLabel().equals("X"))))
 {
 button1.setBackground(Color.red);
 button4.setBackground(Color.red);
 button7.setBackground(Color.red);
 JOptionPane.showMessageDialog(null, "1stPlayer WIN"); button1.setLabel(""); button2.setLabel(""); button3.setLabel(""); button4.setLabel(""); button5.setLabel(""); button6.setLabel(""); button7.setLabel(""); button8.setLabel(""); button9.setLabel("");textField1.setText((textField1.getText())+"l");
 button1.setBackground(Color.black);
 button4.setBackground(Color.black);
 button7.setBackground(Color.black);}
 if(((button2.getLabel().equals("X")))&&((button5.getLabel().equals("X")))&&((button8.getLabel().equals("X"))))
 {
 button2.setBackground(Color.red);
 button5.setBackground(Color.red);
 button8.setBackground(Color.red);
 JOptionPane.showMessageDialog(null, "1stPlayer WIN"); button1.setLabel(""); button2.setLabel(""); button3.setLabel(""); button4.setLabel(""); button5.setLabel(""); button6.setLabel(""); button7.setLabel(""); button8.setLabel(""); button9.setLabel("");textField1.setText((textField1.getText())+"l");
 button2.setBackground(Color.black);
 button5.setBackground(Color.black);
 button8.setBackground(Color.black);}
 if(((button3.getLabel().equals("X")))&&((button9.getLabel().equals("X")))&&((button6.getLabel().equals("X"))))
 {
 button9.setBackground(Color.red);
 button6.setBackground(Color.red);
 button3.setBackground(Color.red);
 JOptionPane.showMessageDialog(null, "1stPlayer WIN"); button1.setLabel(""); button2.setLabel(""); button3.setLabel(""); button4.setLabel(""); button5.setLabel(""); button6.setLabel(""); button7.setLabel(""); button8.setLabel(""); button9.setLabel("");textField1.setText((textField1.getText())+"l");
 button9.setBackground(Color.black);
 button6.setBackground(Color.black);
 button3.setBackground(Color.black); }
 if(((button1.getLabel().equals("X")))&&((button5.getLabel().equals("X")))&&((button9.getLabel().equals("X"))))
 {
 button1.setBackground(Color.red);
 button5.setBackground(Color.red);
 button9.setBackground(Color.red);
 JOptionPane.showMessageDialog(null, "1stPlayer WIN"); button1.setLabel(""); button2.setLabel(""); button3.setLabel(""); button4.setLabel(""); button5.setLabel(""); button6.setLabel(""); button7.setLabel(""); button8.setLabel(""); button9.setLabel("");textField1.setText((textField1.getText())+"l");
 button1.setBackground(Color.black);
 button5.setBackground(Color.black);
 button9.setBackground(Color.black); }
 if(((button5.getLabel().equals("X")))&&((button7.getLabel().equals("X")))&&((button3.getLabel().equals("X"))))
 {
 button7.setBackground(Color.red);
 button5.setBackground(Color.red);
 button3.setBackground(Color.red);
 JOptionPane.showMessageDialog(null, "1stPlayer WIN"); button1.setLabel(""); button2.setLabel(""); button3.setLabel(""); button4.setLabel(""); button5.setLabel(""); button6.setLabel(""); button7.setLabel(""); button8.setLabel(""); button9.setLabel("");textField1.setText((textField1.getText())+"l");
 button7.setBackground(Color.black);
 button5.setBackground(Color.black);
 button3.setBackground(Color.black);
 
}}
/** Creates new form XO */
public XO() {
initComponents();
}
/** This method is called from within the constructor to
 * initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
button10 = new java.awt.Button();
button1 = new java.awt.Button();
button2 = new java.awt.Button();
button3 = new java.awt.Button();
button4 = new java.awt.Button();
button5 = new java.awt.Button();
button6 = new java.awt.Button();
button7 = new java.awt.Button();
button8 = new java.awt.Button();
button9 = new java.awt.Button();
label1 = new java.awt.Label();
label2 = new java.awt.Label();
textField1 = new java.awt.TextField();
textField2 = new java.awt.TextField();
button10.setLabel("button10");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
button1.setBackground(new java.awt.Color(0, 0, 0));
button1.setFont(new java.awt.Font("Dialog", 0, 48)); // NOI18N
button1.setForeground(new java.awt.Color(255, 255, 255));
button1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
button1ActionPerformed(evt);
}
});
button2.setBackground(new java.awt.Color(0, 0, 0));
button2.setFont(new java.awt.Font("Dialog", 0, 48)); // NOI18N
button2.setForeground(new java.awt.Color(255, 255, 255));
button2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
button2ActionPerformed(evt);
}
});
button3.setBackground(new java.awt.Color(0, 0, 0));
button3.setFont(new java.awt.Font("Dialog", 0, 48)); // NOI18N
button3.setForeground(new java.awt.Color(255, 255, 255));
button3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
button3ActionPerformed(evt);
}
});
button4.setBackground(new java.awt.Color(0, 0, 0));
button4.setFont(new java.awt.Font("Dialog", 0, 48)); // NOI18N
button4.setForeground(new java.awt.Color(255, 255, 255));
button4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
button4ActionPerformed(evt);
}
});
button5.setBackground(new java.awt.Color(0, 0, 0));
button5.setFont(new java.awt.Font("Dialog", 0, 48)); // NOI18N
button5.setForeground(new java.awt.Color(255, 255, 255));
button5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
button5ActionPerformed(evt);
}
});
button6.setBackground(new java.awt.Color(0, 0, 0));
button6.setFont(new java.awt.Font("Dialog", 0, 48)); // NOI18N
button6.setForeground(new java.awt.Color(255, 255, 255));
button6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
button6ActionPerformed(evt);
}
});
button7.setBackground(new java.awt.Color(0, 0, 0));
button7.setFont(new java.awt.Font("Dialog", 0, 48)); // NOI18N
button7.setForeground(new java.awt.Color(255, 255, 255));
button7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
button7ActionPerformed(evt);
}
});
button8.setBackground(new java.awt.Color(0, 0, 0));
button8.setFont(new java.awt.Font("Dialog", 0, 48)); // NOI18N
button8.setForeground(new java.awt.Color(255, 255, 255));
button8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
button8ActionPerformed(evt);
}
});
button9.setBackground(new java.awt.Color(0, 0, 0));
button9.setFont(new java.awt.Font("Dialog", 0, 48)); // NOI18N
button9.setForeground(new java.awt.Color(255, 255, 255));
button9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
button9ActionPerformed(evt);
}
});
label1.setText("Player 1");
label2.setText("Player 2");
textField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
textField1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(button2, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(button3, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(button7, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(button4, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(button8, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(button9, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(button5, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(button6, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(textField1, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(textField2, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(36, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(57, 57, 57)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(button2, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(button3, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(71, 71, 71)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(textField2, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
.addComponent(textField1, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(button5, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(button4, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(button6, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(button7, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(button9, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(button8, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(38, 38, 38))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void button1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button1ActionPerformed
if(button1.getLabel().equals("")){
z++;
if(x==1)
 {
 x=2;
button1.setLabel("X");
 z++;
 }
 else
 {
 z++;x=1;
 button1.setLabel("O");}}
check();
checko();drawzz();
}//GEN-LAST:event_button1ActionPerformed
private void button2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button2ActionPerformed
if(button2.getLabel().equals("")){
z=z+1;
if(x==1)
 {
 x=2;
button2.setLabel("X");
 }
 else
 {
 x=1;
 button2.setLabel("O");}check();checko();drawzz();
}
}//GEN-LAST:event_button2ActionPerformed
private void button3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button3ActionPerformed
 if(button3.getLabel().equals("")){
 z=z+1;
 
if(x==1)
 {
 x=2;
button3.setLabel("X");
 }
 else
 {
 x=1;
 button3.setLabel("O");}check();checko();drawzz();}
}//GEN-LAST:event_button3ActionPerformed
private void button4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button4ActionPerformed
 if(button4.getLabel().equals("")){z=z+1;
if(x==1)
 {
 x=2;
button4.setLabel("X");
 }
 else
 {
 x=1;
 button4.setLabel("O");}check();checko();drawzz();}
}//GEN-LAST:event_button4ActionPerformed
private void button5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button5ActionPerformed
 if(button5.getLabel().equals("")){z=z+1;
if(x==1)
 {
 x=2;
button5.setLabel("X");
 }
 else
 {
 x=1;
 button5.setLabel("O");}check();checko();drawzz();}
}//GEN-LAST:event_button5ActionPerformed
private void button6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button6ActionPerformed
if(button6.getLabel().equals("")){ z=z+1;if(x==1)
 {
 x=2;
button6.setLabel("X");
 }
 else
 {
 x=1;
 button6.setLabel("O");}check();checko();drawzz();}
}//GEN-LAST:event_button6ActionPerformed
private void button7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button7ActionPerformed
 if(button7.getLabel().equals("")){z=z+1;
 if(x==1)
 {
 x=2;
button7.setLabel("X");
 }
 else
 {
 x=1;
 button7.setLabel("O");}check();checko();drawzz();}
}//GEN-LAST:event_button7ActionPerformed
private void button8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button8ActionPerformed
 if(button8.getLabel().equals("")){z=z+1;
 if(x==1)
 {
 x=2;
button8.setLabel("X");
 }
 else
 {
 x=1;
 button8.setLabel("O");}check();checko();drawzz();}
}//GEN-LAST:event_button8ActionPerformed
private void button9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button9ActionPerformed
 if(button9.getLabel().equals("")){ z=z+1; if(x==1)
 {
 x=2;
button9.setLabel("X");
 }
 else
 {
 x=1;
 button9.setLabel("O");}check();checko();drawzz();}
}//GEN-LAST:event_button9ActionPerformed
private void textField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textField1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_textField1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new XO().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private java.awt.Button button1;
private java.awt.Button button10;
private java.awt.Button button2;
private java.awt.Button button3;
private java.awt.Button button4;
private java.awt.Button button5;
private java.awt.Button button6;
private java.awt.Button button7;
private java.awt.Button button8;
private java.awt.Button button9;
private java.awt.Label label1;
private java.awt.Label label2;
private java.awt.TextField textField1;
private java.awt.TextField textField2;
// End of variables declaration//GEN-END:variables
}

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
7/26/2010 1:44:40 AMPraveenmax

did u made using net beans???...very unreadable .
(If this comment was disrespectful, please report it.)

 
Add Your Feedback!

Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.